forked from canonical/jimm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return cloud-credentials with empty attribute (canonical#1333)
* return cloud-credentials with empty attribute * set empty map if attributes not found * change application logic to not return error on empty attributes * add app layer test * return empty map rather than nil * fix test
- Loading branch information
Showing
3 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ package jimm_test | |
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
@@ -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 | ||
|
@@ -1549,6 +1554,7 @@ var getCloudCredentialAttributesTests = []struct { | |
username string | ||
hidden bool | ||
jimmAdmin bool | ||
cred string | ||
expectAttributes map[string]string | ||
expectRedacted []string | ||
expectError string | ||
|
@@ -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: map[string]string{}, | ||
expectRedacted: nil, | ||
}, { | ||
name: "OwnerWithHidden", | ||
username: "[email protected]", | ||
hidden: true, | ||
cred: "cred-1", | ||
expectAttributes: map[string]string{ | ||
"client-email": "[email protected]", | ||
"client-id": "1234", | ||
|
@@ -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", | ||
|
@@ -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, | ||
}} | ||
|
@@ -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) | ||
|
@@ -1714,7 +1733,7 @@ func TestCloudCredentialAttributeStore(t *testing.T) { | |
|
||
// Update to an "empty" credential | ||
args.Credential.AuthType = "empty" | ||
args.Credential.Attributes = nil | ||
args.Credential.Attributes = map[string]string{} | ||
_, err = j.UpdateCloudCredential(ctx, user, args) | ||
c.Assert(err, qt.IsNil) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -729,6 +729,33 @@ func (s *cloudSuite) TestCredentialContents(c *gc.C) { | |
}}) | ||
} | ||
|
||
func (s *cloudSuite) TestCredentialContentsWithEmptyAttributes(c *gc.C) { | ||
conn := s.open(c, nil, "test") | ||
defer conn.Close() | ||
client := cloudapi.NewClient(conn) | ||
credentialTag := names.NewCloudCredentialTag(jimmtest.TestCloudName + "/[email protected]/cred3") | ||
err := client.AddCredential( | ||
credentialTag.String(), | ||
cloud.NewCredential( | ||
"certificate", | ||
nil, | ||
), | ||
) | ||
c.Assert(err, gc.Equals, nil) | ||
creds, err := client.CredentialContents(jimmtest.TestCloudName, "cred3", false) | ||
c.Assert(err, gc.Equals, nil) | ||
c.Assert(creds, jc.DeepEquals, []jujuparams.CredentialContentResult{{ | ||
Result: &jujuparams.ControllerCredentialInfo{ | ||
Content: jujuparams.CredentialContent{ | ||
Name: "cred3", | ||
Cloud: jimmtest.TestCloudName, | ||
AuthType: "certificate", | ||
Attributes: nil, | ||
}, | ||
}, | ||
}}) | ||
} | ||
|
||
func (s *cloudSuite) TestRemoveCloud(c *gc.C) { | ||
conn := s.open(c, nil, "test") | ||
defer conn.Close() | ||
|