Skip to content

Commit

Permalink
add app layer test
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed Aug 29, 2024
1 parent b66f8e6 commit f594b5f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion internal/jimm/cloudcredential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package jimm_test
import (
"context"
"database/sql"
"fmt"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -1538,6 +1539,10 @@ cloud-credentials:
client-id: 1234
private-key: super-secret
project-id: 5678
- name: cred-2
cloud: test-cloud
owner: [email protected]
auth-type: certificate
users:
- username: [email protected]
controller-access: superuser
Expand All @@ -1549,6 +1554,7 @@ var getCloudCredentialAttributesTests = []struct {
username string
hidden bool
jimmAdmin bool
cred string
expectAttributes map[string]string
expectRedacted []string
expectError string
Expand All @@ -1557,16 +1563,25 @@ var getCloudCredentialAttributesTests = []struct {
name: "OwnerNoHidden",
username: "[email protected]",
jimmAdmin: true,
cred: "cred-1",
expectAttributes: map[string]string{
"client-email": "[email protected]",
"client-id": "1234",
"project-id": "5678",
},
expectRedacted: []string{"private-key"},
}, {
name: "OwnerNoAttributes",
username: "[email protected]",
jimmAdmin: true,
cred: "cred-2",
expectAttributes: nil,
expectRedacted: nil,
}, {
name: "OwnerWithHidden",
username: "[email protected]",
hidden: true,
cred: "cred-1",
expectAttributes: map[string]string{
"client-email": "[email protected]",
"client-id": "1234",
Expand All @@ -1577,6 +1592,7 @@ var getCloudCredentialAttributesTests = []struct {
name: "SuperUserNoHidden",
username: "[email protected]",
jimmAdmin: true,
cred: "cred-1",
expectAttributes: map[string]string{
"client-email": "[email protected]",
"client-id": "1234",
Expand All @@ -1588,11 +1604,13 @@ var getCloudCredentialAttributesTests = []struct {
username: "[email protected]",
hidden: true,
jimmAdmin: true,
cred: "cred-1",
expectError: `unauthorized`,
expectErrorCode: errors.CodeUnauthorized,
}, {
name: "OtherUserUnauthorized",
username: "[email protected]",
cred: "cred-1",
expectError: `unauthorized`,
expectErrorCode: errors.CodeUnauthorized,
}}
Expand Down Expand Up @@ -1623,7 +1641,8 @@ func TestGetCloudCredentialAttributes(t *testing.T) {
env.PopulateDBAndPermissions(c, j.ResourceTag(), j.Database, client)
u := env.User("[email protected]").DBObject(c, j.Database)
userBob := openfga.NewUser(&u, client)
cred, err := j.GetCloudCredential(ctx, userBob, names.NewCloudCredentialTag("test-cloud/[email protected]/cred-1"))
credTag := fmt.Sprintf("test-cloud/[email protected]/%s", test.cred)
cred, err := j.GetCloudCredential(ctx, userBob, names.NewCloudCredentialTag(credTag))
c.Assert(err, qt.IsNil)

u = env.User(test.username).DBObject(c, j.Database)
Expand Down

0 comments on commit f594b5f

Please sign in to comment.