MCPcopy
hub / github.com/ory/hydra / TestGetLoginRequest

Function TestGetLoginRequest

consent/handler_test.go:97–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

95}
96
97func TestGetLoginRequest(t *testing.T) {
98 t.Parallel()
99
100 reg := testhelpers.NewRegistryMemory(t)
101
102 h := NewHandler(reg)
103 r := httprouterx.NewTestRouterAdminWithPrefix(t)
104 h.SetRoutes(r)
105 ts := httptest.NewServer(r)
106 defer ts.Close()
107
108 cl := &client.Client{
109 ID: "test client id",
110 Name: "test client name",
111 }
112
113 requestURL := "http://192.0.2.1"
114
115 f := &flow.Flow{
116 Client: cl,
117 RequestURL: requestURL,
118 RequestedAt: time.Now(),
119 State: flow.FlowStateLoginUnused,
120 NID: reg.Persister().NetworkID(t.Context()),
121 RequestedAudience: []string{"audience1", "audience2"},
122 RequestedScope: []string{"scope1", "scope2"},
123 Subject: "test subject",
124 SessionID: "test session id",
125 }
126
127 unhandledChallenge, err := f.ToLoginChallenge(t.Context(), reg)
128 require.NoError(t, err)
129
130 t.Run("unhandled flow", func(t *testing.T) {
131 resp, err := ts.Client().Get(ts.URL + "/admin" + LoginPath + "?challenge=" + unhandledChallenge)
132 require.NoError(t, err)
133 require.EqualValues(t, http.StatusOK, resp.StatusCode)
134
135 var result flow.LoginRequest
136 require.NoError(t, json.NewDecoder(resp.Body).Decode(&result))
137 assert.Equal(t, unhandledChallenge, result.ID)
138 assert.Equal(t, requestURL, result.RequestURL)
139 assert.NotNil(t, result.Client)
140 })
141
142 t.Run("handled flow", func(t *testing.T) {
143 f.State = flow.FlowStateLoginUnused
144 require.NoError(t, f.InvalidateLoginRequest())
145 handledChallenge, err := f.ToLoginChallenge(t.Context(), reg)
146 require.NoError(t, err)
147
148 resp, err := ts.Client().Get(ts.URL + "/admin" + LoginPath + "?challenge=" + handledChallenge)
149 require.NoError(t, err)
150 require.EqualValues(t, http.StatusGone, resp.StatusCode)
151
152 var result flow.OAuth2RedirectTo
153 require.NoError(t, json.NewDecoder(resp.Body).Decode(&result))
154 assert.Equal(t, requestURL, result.RedirectTo)

Callers

nothing calls this directly

Calls 12

SetRoutesMethod · 0.95
ToLoginChallengeMethod · 0.95
NewRegistryMemoryFunction · 0.92
NewHandlerFunction · 0.70
CloseMethod · 0.65
NowMethod · 0.65
NetworkIDMethod · 0.65
PersisterMethod · 0.65
GetMethod · 0.65
ClientMethod · 0.65
DecodeMethod · 0.65

Tested by

no test coverage detected