-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
342 additions
and
166 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 |
---|---|---|
|
@@ -156,6 +156,64 @@ func TestGetCloud(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestDefaultCloud(t *testing.T) { | ||
c := qt.New(t) | ||
|
||
client, _, _, err := jimmtest.SetupTestOFGAClient(c.Name()) | ||
c.Assert(err, qt.IsNil) | ||
|
||
ctx := context.Background() | ||
now := time.Now().UTC().Round(time.Millisecond) | ||
j := &jimm.JIMM{ | ||
UUID: uuid.NewString(), | ||
OpenFGAClient: client, | ||
Database: db.Database{ | ||
DB: jimmtest.PostgresDB(c, func() time.Time { return now }), | ||
}, | ||
} | ||
|
||
err = j.Database.Migrate(ctx, false) | ||
c.Assert(err, qt.IsNil) | ||
|
||
aliceIdentity, err := dbmodel.NewIdentity("[email protected]") | ||
c.Assert(err, qt.IsNil) | ||
alice := openfga.NewUser( | ||
aliceIdentity, | ||
client, | ||
) | ||
|
||
cloud := &dbmodel.Cloud{ | ||
Name: "test-cloud-1", | ||
} | ||
err = j.Database.AddCloud(ctx, cloud) | ||
c.Assert(err, qt.IsNil) | ||
|
||
cloud2 := &dbmodel.Cloud{ | ||
Name: "test-cloud-2", | ||
} | ||
err = j.Database.AddCloud(ctx, cloud2) | ||
c.Assert(err, qt.IsNil) | ||
|
||
// Test access to 0 clouds. | ||
_, err = j.DefaultCloud(ctx, alice) | ||
c.Assert(err, qt.ErrorMatches, "no clouds available") | ||
|
||
// Test access to 1 cloud. | ||
err = alice.SetCloudAccess(context.Background(), cloud.ResourceTag(), ofganames.AdministratorRelation) | ||
c.Assert(err, qt.IsNil) | ||
|
||
defaultCloud, err := j.DefaultCloud(ctx, alice) | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(defaultCloud.String(), qt.Equals, "cloud-test-cloud-1") | ||
|
||
// Test access to more than 1 cloud. | ||
err = alice.SetCloudAccess(context.Background(), cloud2.ResourceTag(), ofganames.AdministratorRelation) | ||
c.Assert(err, qt.IsNil) | ||
|
||
_, err = j.DefaultCloud(ctx, alice) | ||
c.Assert(err, qt.ErrorMatches, "multiple clouds available; please specify one") | ||
} | ||
|
||
func TestForEachCloud(t *testing.T) { | ||
c := qt.New(t) | ||
|
||
|
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 |
---|---|---|
|
@@ -36,6 +36,7 @@ func TestModelCreateArgs(t *testing.T) { | |
tests := []struct { | ||
about string | ||
args jujuparams.ModelCreateArgs | ||
defaults jimm.ModelCreateDefaults | ||
expectedArgs jimm.ModelCreateArgs | ||
expectedError string | ||
}{{ | ||
|
@@ -105,13 +106,30 @@ func TestModelCreateArgs(t *testing.T) { | |
}, | ||
expectedError: "owner tag not specified", | ||
}, { | ||
about: "cloud tag not specified", | ||
about: "cloud tag not specified and no default configured", | ||
args: jujuparams.ModelCreateArgs{ | ||
Name: "test-model", | ||
OwnerTag: names.NewUserTag("[email protected]").String(), | ||
CloudCredentialTag: names.NewCloudCredentialTag("test-cloud/alice/test-credential-1").String(), | ||
}, | ||
expectedError: "no cloud specified for model; please specify one", | ||
}, { | ||
about: "cloud tag not specified but default is available", | ||
args: jujuparams.ModelCreateArgs{ | ||
Name: "test-model", | ||
OwnerTag: names.NewUserTag("[email protected]").String(), | ||
CloudCredentialTag: names.NewCloudCredentialTag("test-cloud/alice/test-credential-1").String(), | ||
}, | ||
defaults: jimm.ModelCreateDefaults{ | ||
DefaultCloud: func() (names.CloudTag, error) { | ||
return names.NewCloudTag("test-cloud"), nil | ||
}}, | ||
expectedArgs: jimm.ModelCreateArgs{ | ||
Name: "test-model", | ||
Owner: names.NewUserTag("[email protected]"), | ||
Cloud: names.NewCloudTag("test-cloud"), | ||
CloudCredential: names.NewCloudCredentialTag("test-cloud/alice/test-credential-1"), | ||
}, | ||
}} | ||
|
||
opts := []cmp.Option{ | ||
|
@@ -128,7 +146,7 @@ func TestModelCreateArgs(t *testing.T) { | |
for _, test := range tests { | ||
c.Run(test.about, func(c *qt.C) { | ||
var a jimm.ModelCreateArgs | ||
err := a.FromJujuModelCreateArgs(&test.args) | ||
err := a.FromJujuModelCreateArgs(&test.args, test.defaults) | ||
if test.expectedError == "" { | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(a, qt.CmpEquals(opts...), test.expectedArgs) | ||
|
@@ -924,7 +942,8 @@ func TestAddModel(t *testing.T) { | |
user.JimmAdmin = test.jimmAdmin | ||
|
||
args := jimm.ModelCreateArgs{} | ||
err = args.FromJujuModelCreateArgs(&test.args) | ||
defaults := jimm.ModelCreateDefaults{} | ||
err = args.FromJujuModelCreateArgs(&test.args, defaults) | ||
c.Assert(err, qt.IsNil) | ||
|
||
_, err = j.AddModel(context.Background(), user, &args) | ||
|
@@ -3626,7 +3645,7 @@ controllers: | |
CloudTag: names.NewCloudTag("test-cloud").String(), | ||
CloudRegion: "test-region-1", | ||
CloudCredentialTag: names.NewCloudCredentialTag("test-cloud/[email protected]/test-credential-1").String(), | ||
}) | ||
}, jimm.ModelCreateDefaults{}) | ||
c.Assert(err, qt.IsNil) | ||
|
||
// According to controller priority for test-region-1, we would | ||
|
Oops, something went wrong.