(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func TestAuthentication(t *testing.T) { |
| 89 | store := &mockStore{} |
| 90 | jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) |
| 91 | if err != nil { |
| 92 | panic(err) |
| 93 | } |
| 94 | c := componenttest.NewComponent(t, &component.Config{ |
| 95 | ServiceBase: config.ServiceBase{ |
| 96 | HTTP: config.HTTP{ |
| 97 | Cookie: config.Cookie{ |
| 98 | HashKey: []byte("12345678123456781234567812345678"), |
| 99 | BlockKey: []byte("12345678123456781234567812345678"), |
| 100 | }, |
| 101 | }, |
| 102 | }, |
| 103 | }) |
| 104 | s, err := account.NewServer(c, store, oauth.Config{ |
| 105 | Mount: "/oauth", |
| 106 | CSRFAuthKey: []byte("12345678123456781234567812345678"), |
| 107 | UI: oauth.UIConfig{ |
| 108 | TemplateData: webui.TemplateData{ |
| 109 | SiteName: "The Things Network", |
| 110 | Title: "Account", |
| 111 | CanonicalURL: "https://example.com/oauth", |
| 112 | }, |
| 113 | }, |
| 114 | }, identityserver.GenerateCSPString) |
| 115 | if err != nil { |
| 116 | panic(err) |
| 117 | } |
| 118 | c.RegisterWeb(s) |
| 119 | componenttest.StartComponent(t, c) |
| 120 | |
| 121 | var csrfToken string |
| 122 | var r *http.Request |
| 123 | |
| 124 | // Obtain CSRF token. |
| 125 | r = httptest.NewRequest("GET", "/oauth/login", nil) |
| 126 | r.URL.Scheme, r.URL.Host = "http", r.Host |
| 127 | if err != nil { |
| 128 | t.Fatal(err) |
| 129 | } |
| 130 | |
| 131 | rr := httptest.NewRecorder() |
| 132 | c.ServeHTTP(rr, r) |
| 133 | csrfToken = rr.Header().Get("X-CSRF-Token") |
| 134 | |
| 135 | if cookies := rr.Result().Cookies(); len(cookies) > 0 { |
| 136 | jar.SetCookies(r.URL, cookies) |
| 137 | } |
| 138 | |
| 139 | for _, tt := range []struct { |
| 140 | Name string |
| 141 | StoreSetup func(*mockStore) |
| 142 | StoreCheck func(*testing.T, *mockStore) |
| 143 | Method string |
| 144 | Path string |
| 145 | Body any |
nothing calls this directly
no test coverage detected