MCPcopy Create free account
hub / github.com/crewjam/saml / TestMiddlewareQueryAttributes

Function TestMiddlewareQueryAttributes

samlsp/middleware_attribute_query_test.go:245–274  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

243}
244
245func 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
276func TestMiddlewareQueryAttributesErrors(t *testing.T) {
277 newRequest := func(cookies ...*http.Cookie) *http.Request {

Callers

nothing calls this directly

Calls 7

newLogoutTestFunction · 0.85
newAQTestAuthorityFunction · 0.85
loginCookieMethod · 0.80
RequireAccountMethod · 0.80
ServeHTTPMethod · 0.80
LenMethod · 0.80
QueryAttributesMethod · 0.45

Tested by

no test coverage detected