MCPcopy Create free account
hub / github.com/UiPath/uipathcli / TestMissingCodeShowsErrorMessage

Function TestMissingCodeShowsErrorMessage

auth/oauth_authenticator_test.go:325–350  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

323}
324
325func TestMissingCodeShowsErrorMessage(t *testing.T) {
326 identityUrl, _ := url.Parse("http://localhost")
327 ctx := createNonConfidentialAuthContext(*identityUrl)
328 loginUrl, _ := callAuthenticator(ctx)
329
330 redirectUri := loginUrl.Query().Get("redirect_uri")
331 state := loginUrl.Query().Get("state")
332 request, err := http.NewRequestWithContext(t.Context(), http.MethodGet, redirectUri+"?code=&state="+state, nil)
333 if err != nil {
334 t.Fatalf("Unexpected error calling login url: %v", err)
335 }
336 response, err := http.DefaultClient.Do(request)
337 if err != nil {
338 t.Fatalf("Unexpected error calling login url: %v", err)
339 }
340 defer func() { _ = response.Body.Close() }()
341
342 responseBody, err := io.ReadAll(response.Body)
343 if err != nil {
344 t.Fatalf("Login url response body cannot be read: %v", err)
345 }
346
347 if string(responseBody) != "Could not find query string 'code' in redirect_url" {
348 t.Errorf("Expected error message that state does not match, but got: %v", string(responseBody))
349 }
350}
351
352func TestOAuthFlowRedactsClientSecretAndRefreshToken(t *testing.T) {
353 identityServerFake := identityServerFake{

Callers

nothing calls this directly

Calls 6

callAuthenticatorFunction · 0.85
QueryMethod · 0.80
CloseMethod · 0.80
ParseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected