MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestOAuthFlow

Function TestOAuthFlow

pkg/oauth/server_test.go:128–545  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

126}
127
128func TestOAuthFlow(t *testing.T) {
129 store := &mockStore{}
130 jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
131 if err != nil {
132 panic(err)
133 }
134 c := componenttest.NewComponent(t, &component.Config{
135 ServiceBase: config.ServiceBase{
136 HTTP: config.HTTP{
137 Cookie: config.Cookie{
138 HashKey: []byte("12345678123456781234567812345678"),
139 BlockKey: []byte("12345678123456781234567812345678"),
140 },
141 },
142 },
143 })
144 s, err := oauth.NewServer(c, store, oauth.Config{
145 Mount: "/oauth",
146 CSRFAuthKey: []byte("12345678123456781234567812345678"),
147 UI: oauth.UIConfig{
148 TemplateData: webui.TemplateData{
149 SiteName: "The Things Network",
150 Title: "OAuth",
151 CanonicalURL: "https://example.com/oauth",
152 },
153 },
154 }, identityserver.GenerateCSPString)
155 if err != nil {
156 panic(err)
157 }
158 c.RegisterWeb(s)
159 componenttest.StartComponent(t, c)
160
161 var csrfToken string
162 var r *http.Request
163
164 // Obtain CSRF token.
165 r = httptest.NewRequest("GET", "/oauth/login", nil)
166 r.URL.Scheme, r.URL.Host = "http", r.Host
167 if err != nil {
168 t.Fatal(err)
169 }
170
171 rr := httptest.NewRecorder()
172 c.ServeHTTP(rr, r)
173 csrfToken = rr.Header().Get("X-CSRF-Token")
174
175 if cookies := rr.Result().Cookies(); len(cookies) > 0 {
176 jar.SetCookies(r.URL, cookies)
177 }
178
179 for _, tt := range []struct {
180 Name string
181 StoreSetup func(*mockStore)
182 StoreCheck func(*testing.T, *mockStore)
183 UseCookie *http.Cookie
184 Method string
185 Path string

Callers

nothing calls this directly

Calls 15

RegisterWebMethod · 0.95
ServeHTTPMethod · 0.95
resetMethod · 0.95
NewServerFunction · 0.92
HeaderMethod · 0.80
NewMethod · 0.65
FatalMethod · 0.65
GetMethod · 0.65
ResultMethod · 0.65
RunMethod · 0.65
SetMethod · 0.65
MarshalMethod · 0.65

Tested by

no test coverage detected