Skip to content

Commit

Permalink
tests: add unit tests for provider check
Browse files Browse the repository at this point in the history
  • Loading branch information
natalian98 committed Apr 19, 2024
1 parent b75313e commit 22f6e82
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pkg/kratos/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,3 +1001,42 @@ func TestParseLoginFlowPasswordMethodBody(t *testing.T) {
t.Fatalf("expected error to be nil not %v", err)
}
}

func TestGetProviderNameWhenNotOidcMethod(t *testing.T) {
loginFlow := &kClient.UpdateLoginFlowBody{}
service := NewService(nil, nil, nil, nil, nil, nil)

actualProviderName := service.getProviderName(loginFlow)

expectedProviderName := ""
if expectedProviderName != actualProviderName {
t.Fatalf("Expected the provider to be %v, not %v", expectedProviderName, actualProviderName)
}
}

func TestGetProviderNameOidc(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

expectedProviderName := "someProvider"
mockLogger := NewMockLoggerInterface(ctrl)
mockHydra := NewMockHydraClientInterface(ctrl)
mockKratos := NewMockKratosClientInterface(ctrl)
mockAuthz := NewMockAuthorizerInterface(ctrl)
mockTracer := NewMockTracingInterface(ctrl)
mockMonitor := monitoring.NewMockMonitorInterface(ctrl)

flow := kClient.NewUpdateLoginFlowWithOidcMethod("", expectedProviderName)

body := kClient.UpdateLoginFlowWithOidcMethodAsUpdateLoginFlowBody(flow)
jsonBody, _ := body.MarshalJSON()

req := httptest.NewRequest(http.MethodPost, "http://some/path", io.NopCloser(bytes.NewBuffer(jsonBody)))

b, _ := NewService(mockKratos, mockHydra, mockAuthz, mockTracer, mockMonitor, mockLogger).ParseLoginFlowMethodBody(req)

actualProviderName := b.UpdateLoginFlowWithOidcMethod.Provider
if expectedProviderName != actualProviderName {
t.Fatalf("Expected the provider to be %v, not %v", expectedProviderName, actualProviderName)
}
}

0 comments on commit 22f6e82

Please sign in to comment.