(t *testing.T)
| 243 | } |
| 244 | |
| 245 | func TestMiddlewareQueryAttributes(t *testing.T) { |
| 246 | lt := newLogoutTest(t) |
| 247 | authority := newAQTestAuthority(t, lt) |
| 248 | cookie := lt.loginCookie(t, aqTestNameID) |
| 249 | |
| 250 | var result *saml.AttributeQueryResult |
| 251 | var queryErr error |
| 252 | handler := lt.m.RequireAccount(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { |
| 253 | result, queryErr = lt.m.QueryAttributes(r, saml.Attribute{Name: aqTestMailOID, NameFormat: aqTestURINameFormat}) |
| 254 | })) |
| 255 | req := httptest.NewRequest(http.MethodGet, "https://sp.example.com/profile", nil) |
| 256 | req.AddCookie(cookie) |
| 257 | handler.ServeHTTP(httptest.NewRecorder(), req) |
| 258 | |
| 259 | assert.NilError(t, queryErr) |
| 260 | assert.Assert(t, is.Len(result.Attributes, 1)) |
| 261 | assert.Check(t, is.Equal(result.Attributes[0].Values[0].Value, "alice@example.com")) |
| 262 | |
| 263 | // The query names the user by the NameID of the login, Format and |
| 264 | // qualifiers included. |
| 265 | assert.Assert(t, is.Len(authority.queries, 1)) |
| 266 | assert.Check(t, is.DeepEqual(*authority.queries[0].Subject.NameID, aqTestNameID)) |
| 267 | assert.Check(t, is.Len(authority.queries[0].Attributes, 1)) |
| 268 | |
| 269 | // Without RequireAccount, the session is read from the request. |
| 270 | result, queryErr = lt.m.QueryAttributes(req) |
| 271 | assert.NilError(t, queryErr) |
| 272 | assert.Check(t, is.Len(result.Attributes, 1)) |
| 273 | assert.Check(t, is.Len(authority.queries, 2)) |
| 274 | } |
| 275 | |
| 276 | func TestMiddlewareQueryAttributesErrors(t *testing.T) { |
| 277 | newRequest := func(cookies ...*http.Cookie) *http.Request { |
nothing calls this directly
no test coverage detected