Skip to content

Commit

Permalink
rpc: fix missing AuthConfig in GetTenant (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrislav authored Jul 10, 2024
1 parent d5f6f3d commit 4307e72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions rpc/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (s *RPC) GetTenant(ctx context.Context, projectID uint64) (*proto.Tenant, e
Version: tnt.Version,
OIDCProviders: tenantData.OIDCProviders,
AllowedOrigins: tenantData.AllowedOrigins,
AuthConfig: &tenantData.AuthConfig,
UpdatedAt: tnt.CreatedAt,
}
return retTenant, nil
Expand Down
16 changes: 13 additions & 3 deletions rpc/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ func TestRPC_GetTenant(t *testing.T) {
svc := initRPC(t)

tenant, _ := newTenant(t, svc.Enclave, issuer)
tenant2, _ := newTenantWithAuthConfig(t, svc.Enclave, proto.AuthConfig{Email: proto.AuthEmailConfig{Enabled: true}})
require.NoError(t, svc.Tenants.Add(context.Background(), tenant))
require.NoError(t, svc.Tenants.Add(context.Background(), tenant2))

srv := httptest.NewServer(svc.Handler())
defer srv.Close()
Expand All @@ -33,15 +35,23 @@ func TestRPC_GetTenant(t *testing.T) {
require.NoError(t, err)

t.Run("ExistingTenant", func(t *testing.T) {
tnt, err := c.GetTenant(ctx, 1)
tnt, err := c.GetTenant(ctx, tenant.ProjectID)
require.NoError(t, err)
assert.NotEmpty(t, tnt)
assert.Equal(t, uint64(1), tnt.ProjectID)
assert.Equal(t, tenant.ProjectID, tnt.ProjectID)
assert.Equal(t, validation.Origins{"http://localhost"}, tnt.AllowedOrigins)
})

t.Run("ExistingTenantWithAuthConfig", func(t *testing.T) {
tnt, err := c.GetTenant(ctx, tenant2.ProjectID)
require.NoError(t, err)
assert.NotEmpty(t, tnt)
assert.Equal(t, tenant2.ProjectID, tnt.ProjectID)
assert.True(t, tnt.AuthConfig.Email.Enabled)
})

t.Run("MissingTenant", func(t *testing.T) {
tnt, err := c.GetTenant(ctx, 2)
tnt, err := c.GetTenant(ctx, 12345)
assert.ErrorIs(t, err, proto.ErrTenantNotFound)
assert.Nil(t, tnt)
})
Expand Down

0 comments on commit 4307e72

Please sign in to comment.