Skip to content

Commit

Permalink
Merge branch 'feature-oidc' into css-7081/use-secret-store
Browse files Browse the repository at this point in the history
  • Loading branch information
babakks authored Mar 18, 2024
2 parents aaa14c5 + 12c20db commit 951086f
Show file tree
Hide file tree
Showing 27 changed files with 92 additions and 82 deletions.
4 changes: 2 additions & 2 deletions cmd/jaas/cmd/addserviceaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = gc.Suite(&addServiceAccountSuite{})
func (s *addServiceAccountSuite) TestAddServiceAccount(c *gc.C) {
clientID := "abda51b2-d735-4794-a8bd-49c506baa4af"
// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
_, err := cmdtesting.RunCommand(c, cmd.NewAddServiceAccountCommandForTesting(s.ClientStore(), bClient), clientID)
c.Assert(err, gc.IsNil)
tuple := openfga.Tuple{
Expand All @@ -42,7 +42,7 @@ func (s *addServiceAccountSuite) TestAddServiceAccount(c *gc.C) {
_, err = cmdtesting.RunCommand(c, cmd.NewAddServiceAccountCommandForTesting(s.ClientStore(), bClient), clientID)
c.Assert(err, gc.IsNil)
// Check that re-running the command for a different user returns an error.
bClientBob := jimmtest.NewUserSessionLogin("bob")
bClientBob := jimmtest.NewUserSessionLogin(c, "bob")
_, err = cmdtesting.RunCommand(c, cmd.NewAddServiceAccountCommandForTesting(s.ClientStore(), bClientBob), clientID)
c.Assert(err, gc.ErrorMatches, "service account already owned")
}
4 changes: 2 additions & 2 deletions cmd/jaas/cmd/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *grantSuite) TestGrant(c *gc.C) {
clientID := "abda51b2-d735-4794-a8bd-49c506baa4af"

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")

sa := dbmodel.Identity{
Name: clientID,
Expand Down Expand Up @@ -86,7 +86,7 @@ func (s *grantSuite) TestMissingArgs(c *gc.C) {
expectedError: "user/group not specified",
}}

bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
clientStore := s.ClientStore()
for _, t := range tests {
_, err := cmdtesting.RunCommand(c, cmd.NewGrantCommandForTesting(clientStore, bClient), t.args...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/jaas/cmd/listserviceaccountcredentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ aws foo
}
for _, test := range testCases {
c.Log(test.about)
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
var result *jujucmd.Context
if test.showSecrets {
result, err = cmdtesting.RunCommand(c, cmd.NewListServiceAccountCredentialsCommandForTesting(s.ClientStore(), bClient), clientID, "--format", test.format, "--show-secrets")
Expand Down
10 changes: 5 additions & 5 deletions cmd/jaas/cmd/updatecredentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *updateCredentialsSuite) TestUpdateCredentialsWithNewCredentials(c *gc.C
clientID := "abda51b2-d735-4794-a8bd-49c506baa4af"

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")

sa := dbmodel.Identity{
Name: clientID,
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s *updateCredentialsSuite) TestUpdateCredentialsWithExistingCredentials(c
clientID := "abda51b2-d735-4794-a8bd-49c506baa4af"

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")

sa := dbmodel.Identity{
Name: clientID,
Expand Down Expand Up @@ -157,7 +157,7 @@ func (s *updateCredentialsSuite) TestUpdateCredentialsWithExistingCredentials(c
}

func (s *updateCredentialsSuite) TestCloudNotInLocalStore(c *gc.C) {
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
_, err := cmdtesting.RunCommand(c, cmd.NewUpdateCredentialsCommandForTesting(s.ClientStore(), bClient),
"00000000-0000-0000-0000-000000000000",
"non-existing-cloud",
Expand All @@ -167,7 +167,7 @@ func (s *updateCredentialsSuite) TestCloudNotInLocalStore(c *gc.C) {
}

func (s *updateCredentialsSuite) TestCredentialNotInLocalStore(c *gc.C) {
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")

clientStore := s.ClientStore()
err := clientStore.UpdateCredential("some-cloud", jujucloud.CloudCredential{
Expand Down Expand Up @@ -208,7 +208,7 @@ func (s *updateCredentialsSuite) TestMissingArgs(c *gc.C) {
expectedError: "too many args",
}}

bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
clientStore := s.ClientStore()
for _, t := range tests {
_, err := cmdtesting.RunCommand(c, cmd.NewUpdateCredentialsCommandForTesting(clientStore, bClient), t.args...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/jimmctl/cmd/addcloudtocontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ clouds:
c.Log(test.about)
tmpfile, cleanupFunc := writeTempFile(c, test.cloudInfo)

bClient := jimmtest.NewUserSessionLogin("[email protected]")
bClient := jimmtest.NewUserSessionLogin(c, "[email protected]")
// Running the command succeeds
newCmd := cmd.NewAddCloudToControllerCommandForTesting(s.ClientStore(), bClient, test.cloudByNameFunc)
var err error
Expand Down
4 changes: 2 additions & 2 deletions cmd/jimmctl/cmd/addcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *addControllerSuite) TestAddControllerSuperuser(c *gc.C) {
defer os.RemoveAll(tmpdir)

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
ctx, err := cmdtesting.RunCommand(c, cmd.NewAddControllerCommandForTesting(s.ClientStore(), bClient), tmpfile)
c.Assert(err, gc.IsNil)
c.Assert(cmdtesting.Stdout(ctx), gc.Matches, `name: controller-1
Expand Down Expand Up @@ -101,7 +101,7 @@ func (s *addControllerSuite) TestAddController(c *gc.C) {
defer os.RemoveAll(tmpdir)

// bob is not superuser
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewAddControllerCommandForTesting(s.ClientStore(), bClient), tmpfile)
c.Assert(err, gc.ErrorMatches, `unauthorized \(unauthorized access\)`)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/jimmctl/cmd/crossmodelquery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var _ = gc.Suite(&crossModelQuerySuite{})
func (s *crossModelQuerySuite) TestCrossModelQueryCommand(c *gc.C) {
// Test setup.
store := s.ClientStore()
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")

s.AddController(c, "controller-2", s.APIInfo(c))
cct := names.NewCloudCredentialTag(jimmtest.TestCloudName + "/[email protected]/cred")
Expand Down
4 changes: 2 additions & 2 deletions cmd/jimmctl/cmd/grantauditlogaccess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ type grantAuditLogAccessSuite struct {

func (s *grantAuditLogAccessSuite) TestGrantAuditLogAccessSuperuser(c *gc.C) {
// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
_, err := cmdtesting.RunCommand(c, cmd.NewGrantAuditLogAccessCommandForTesting(s.ClientStore(), bClient), "[email protected]")
c.Assert(err, gc.IsNil)
}

func (s *grantAuditLogAccessSuite) TestGrantAuditLogAccess(c *gc.C) {
// bob is not superuser
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewGrantAuditLogAccessCommandForTesting(s.ClientStore(), bClient), "[email protected]")
c.Assert(err, gc.ErrorMatches, `unauthorized \(unauthorized access\)`)
}
18 changes: 9 additions & 9 deletions cmd/jimmctl/cmd/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var _ = gc.Suite(&groupSuite{})

func (s *groupSuite) TestAddGroupSuperuser(c *gc.C) {
// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
_, err := cmdtesting.RunCommand(c, cmd.NewAddGroupCommandForTesting(s.ClientStore(), bClient), "test-group")
c.Assert(err, gc.IsNil)

Expand All @@ -37,14 +37,14 @@ func (s *groupSuite) TestAddGroupSuperuser(c *gc.C) {

func (s *groupSuite) TestAddGroup(c *gc.C) {
// bob is not superuser
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewAddGroupCommandForTesting(s.ClientStore(), bClient), "test-group")
c.Assert(err, gc.ErrorMatches, `unauthorized \(unauthorized access\)`)
}

func (s *groupSuite) TestRenameGroupSuperuser(c *gc.C) {
// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")

err := s.JimmCmdSuite.JIMM.Database.AddGroup(context.TODO(), "test-group")
c.Assert(err, gc.IsNil)
Expand All @@ -61,14 +61,14 @@ func (s *groupSuite) TestRenameGroupSuperuser(c *gc.C) {

func (s *groupSuite) TestRenameGroup(c *gc.C) {
// bob is not superuser
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewRenameGroupCommandForTesting(s.ClientStore(), bClient), "test-group", "renamed-group")
c.Assert(err, gc.ErrorMatches, `unauthorized \(unauthorized access\)`)
}

func (s *groupSuite) TestRemoveGroupSuperuser(c *gc.C) {
// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")

err := s.JimmCmdSuite.JIMM.Database.AddGroup(context.TODO(), "test-group")
c.Assert(err, gc.IsNil)
Expand All @@ -83,22 +83,22 @@ func (s *groupSuite) TestRemoveGroupSuperuser(c *gc.C) {

func (s *groupSuite) TestRemoveGroupWithoutFlag(c *gc.C) {
// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")

_, err := cmdtesting.RunCommand(c, cmd.NewRemoveGroupCommandForTesting(s.ClientStore(), bClient), "test-group")
c.Assert(err.Error(), gc.Matches, "Failed to read from input.")
}

func (s *groupSuite) TestRemoveGroup(c *gc.C) {
// bob is not superuser
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewRemoveGroupCommandForTesting(s.ClientStore(), bClient), "test-group", "-y")
c.Assert(err, gc.ErrorMatches, `unauthorized \(unauthorized access\)`)
}

func (s *groupSuite) TestListGroupsSuperuser(c *gc.C) {
// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")

for i := 0; i < 3; i++ {
err := s.JimmCmdSuite.JIMM.Database.AddGroup(context.TODO(), fmt.Sprint("test-group", i))
Expand All @@ -115,7 +115,7 @@ func (s *groupSuite) TestListGroupsSuperuser(c *gc.C) {

func (s *groupSuite) TestListGroups(c *gc.C) {
// bob is not superuser
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewListGroupsCommandForTesting(s.ClientStore(), bClient), "test-group")
c.Assert(err, gc.ErrorMatches, `unauthorized \(unauthorized access\)`)
}
2 changes: 1 addition & 1 deletion cmd/jimmctl/cmd/importcloudcredentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *importCloudCredentialsSuite) TestImportCloudCredentials(c *gc.C) {
c.Assert(err, gc.IsNil)

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
_, err = cmdtesting.RunCommand(c, cmd.NewImportCloudCredentialsCommandForTesting(s.ClientStore(), bClient), tmpfile)
c.Assert(err, gc.IsNil)

Expand Down
14 changes: 7 additions & 7 deletions cmd/jimmctl/cmd/importmodel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *importModelSuite) TestImportModelSuperuser(c *gc.C) {
defer m.Close()

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
_, err = cmdtesting.RunCommand(c, cmd.NewImportModelCommandForTesting(s.ClientStore(), bClient), "controller-1", m.ModelUUID())
c.Assert(err, gc.IsNil)

Expand All @@ -70,7 +70,7 @@ func (s *importModelSuite) TestImportModelFromLocalUser(c *gc.C) {
c.Assert(err, gc.Equals, nil)

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
_, err = cmdtesting.RunCommand(c, cmd.NewImportModelCommandForTesting(s.ClientStore(), bClient), "controller-1", mt.Id(), "--owner", "[email protected]")
c.Assert(err, gc.IsNil)

Expand Down Expand Up @@ -101,31 +101,31 @@ func (s *importModelSuite) TestImportModelUnauthorized(c *gc.C) {
defer m.Close()

// bob is not superuser
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err = cmdtesting.RunCommand(c, cmd.NewImportModelCommandForTesting(s.ClientStore(), bClient), "controller-1", m.ModelUUID())
c.Assert(err, gc.ErrorMatches, `unauthorized \(unauthorized access\)`)
}

func (s *importModelSuite) TestImportModelNoController(c *gc.C) {
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewImportModelCommandForTesting(s.ClientStore(), bClient))
c.Assert(err, gc.ErrorMatches, `controller not specified`)
}

func (s *importModelSuite) TestImportModelNoModelUUID(c *gc.C) {
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewImportModelCommandForTesting(s.ClientStore(), bClient), "controller-id")
c.Assert(err, gc.ErrorMatches, `model uuid not specified`)
}

func (s *importModelSuite) TestImportModelInvalidModelUUID(c *gc.C) {
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewImportModelCommandForTesting(s.ClientStore(), bClient), "controller-id", "not-a-uuid")
c.Assert(err, gc.ErrorMatches, `invalid model uuid`)
}

func (s *importModelSuite) TestImportModelTooManyArgs(c *gc.C) {
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewImportModelCommandForTesting(s.ClientStore(), bClient), "controller-id", "not-a-uuid", "spare-argument")
c.Assert(err, gc.ErrorMatches, `too many args`)
}
4 changes: 2 additions & 2 deletions cmd/jimmctl/cmd/listauditevents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (s *listAuditEventsSuite) TestListAuditEventsSuperuser(c *gc.C) {
s.AddModel(c, names.NewUserTag("[email protected]"), "model-2", names.NewCloudTag(jimmtest.TestCloudName), jimmtest.TestCloudRegionName, cct)

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
context, err := cmdtesting.RunCommand(c, cmd.NewListAuditEventsCommandForTesting(s.ClientStore(), bClient))
c.Assert(err, gc.IsNil)
c.Assert(cmdtesting.Stdout(context), gc.Matches,
Expand Down Expand Up @@ -66,7 +66,7 @@ func (s *listAuditEventsSuite) TestListAuditEventsStatus(c *gc.C) {
s.AddModel(c, names.NewUserTag("[email protected]"), "model-2", names.NewCloudTag(jimmtest.TestCloudName), jimmtest.TestCloudRegionName, cct)

// bob is not superuser
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewListAuditEventsCommandForTesting(s.ClientStore(), bClient))
c.Assert(err, gc.ErrorMatches, `unauthorized \(unauthorized access\)`)
}
4 changes: 2 additions & 2 deletions cmd/jimmctl/cmd/listcontrollers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *listControllersSuite) TestListControllersSuperuser(c *gc.C) {
s.AddController(c, "controller-1", s.APIInfo(c))

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
context, err := cmdtesting.RunCommand(c, cmd.NewListControllersCommandForTesting(s.ClientStore(), bClient))
c.Assert(err, gc.IsNil)
c.Assert(cmdtesting.Stdout(context), gc.Matches, expectedSuperuserOutput)
Expand All @@ -87,7 +87,7 @@ func (s *listControllersSuite) TestListControllers(c *gc.C) {
s.AddController(c, "controller-1", s.APIInfo(c))

// bob is not superuser
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
context, err := cmdtesting.RunCommand(c, cmd.NewListControllersCommandForTesting(s.ClientStore(), bClient))
c.Assert(err, gc.IsNil)
c.Assert(cmdtesting.Stdout(context), gc.Matches, expectedOutput)
Expand Down
6 changes: 3 additions & 3 deletions cmd/jimmctl/cmd/migratemodel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *migrateModelSuite) TestMigrateModelCommandSuperuser(c *gc.C) {
mt2 := s.AddModel(c, names.NewUserTag("[email protected]"), "model-2", names.NewCloudTag(jimmtest.TestCloudName), jimmtest.TestCloudRegionName, cct)

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
context, err := cmdtesting.RunCommand(c, cmd.NewMigrateModelCommandForTesting(s.ClientStore(), bClient), "controller-1", mt.String(), mt2.String())
c.Assert(err, gc.IsNil)
c.Assert(cmdtesting.Stdout(context), gc.Matches, migrationResultRegex)
Expand All @@ -61,13 +61,13 @@ func (s *migrateModelSuite) TestMigrateModelCommandFailsWithInvalidModelTag(c *g
s.AddModel(c, names.NewUserTag("[email protected]"), "model-2", names.NewCloudTag(jimmtest.TestCloudName), jimmtest.TestCloudRegionName, cct)

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
_, err := cmdtesting.RunCommand(c, cmd.NewMigrateModelCommandForTesting(s.ClientStore(), bClient), "controller-1", "model-001", "model-002")
c.Assert(err, gc.ErrorMatches, ".* is not a valid model tag")
}

func (s *migrateModelSuite) TestMigrateModelCommandFailsWithMissingArgs(c *gc.C) {
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
_, err := cmdtesting.RunCommand(c, cmd.NewMigrateModelCommandForTesting(s.ClientStore(), bClient), "myController")
c.Assert(err, gc.ErrorMatches, "Missing controller and model tag arguments")
}
4 changes: 2 additions & 2 deletions cmd/jimmctl/cmd/modelstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (s *modelStatusSuite) TestModelStatusSuperuser(c *gc.C) {
mt := s.AddModel(c, names.NewUserTag("[email protected]"), "model-2", names.NewCloudTag(jimmtest.TestCloudName), jimmtest.TestCloudRegionName, cct)

// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
context, err := cmdtesting.RunCommand(c, cmd.NewModelStatusCommandForTesting(s.ClientStore(), bClient), mt.Id())
c.Assert(err, gc.IsNil)
c.Assert(cmdtesting.Stdout(context), gc.Matches, expectedModelStatusOutput)
Expand All @@ -75,7 +75,7 @@ func (s *modelStatusSuite) TestModelStatus(c *gc.C) {
mt := s.AddModel(c, names.NewUserTag("[email protected]"), "model-2", names.NewCloudTag(jimmtest.TestCloudName), jimmtest.TestCloudRegionName, cct)

// bob is not superuser
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewModelStatusCommandForTesting(s.ClientStore(), bClient), mt.Id())
c.Assert(err, gc.ErrorMatches, `unauthorized \(unauthorized access\)`)
}
8 changes: 4 additions & 4 deletions cmd/jimmctl/cmd/purge_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var _ = gc.Suite(&purgeLogsSuite{})

func (s *purgeLogsSuite) TestPurgeLogsSuperuser(c *gc.C) {
// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
datastring := "2021-01-01T00:00:00Z"
cmdCtx, err := cmdtesting.RunCommand(c, cmd.NewPurgeLogsCommandForTesting(s.ClientStore(), bClient), datastring)
c.Assert(err, gc.IsNil)
Expand All @@ -34,7 +34,7 @@ func (s *purgeLogsSuite) TestPurgeLogsSuperuser(c *gc.C) {

func (s *purgeLogsSuite) TestInvalidISO8601Date(c *gc.C) {
// alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
datastring := "13/01/2021"
_, err := cmdtesting.RunCommand(c, cmd.NewPurgeLogsCommandForTesting(s.ClientStore(), bClient), datastring)
c.Assert(err, gc.ErrorMatches, `invalid date. Expected ISO8601 date`)
Expand All @@ -43,7 +43,7 @@ func (s *purgeLogsSuite) TestInvalidISO8601Date(c *gc.C) {

func (s *purgeLogsSuite) TestPurgeLogs(c *gc.C) {
// bob is not superuser
bClient := jimmtest.NewUserSessionLogin("bob")
bClient := jimmtest.NewUserSessionLogin(c, "bob")
_, err := cmdtesting.RunCommand(c, cmd.NewPurgeLogsCommandForTesting(s.ClientStore(), bClient), "2021-01-01T00:00:00Z")
c.Assert(err, gc.ErrorMatches, `unauthorized \(unauthorized access\)`)
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func (s *purgeLogsSuite) TestPurgeLogsFromDb(c *gc.C) {

tomorrow := relativeNow.AddDate(0, 0, 1).Format(layout)
//alice is superuser
bClient := jimmtest.NewUserSessionLogin("alice")
bClient := jimmtest.NewUserSessionLogin(c, "alice")
cmdCtx, err := cmdtesting.RunCommand(c, cmd.NewPurgeLogsCommandForTesting(s.ClientStore(), bClient), tomorrow)
c.Assert(err, gc.IsNil)
// check that logs have been deleted
Expand Down
Loading

0 comments on commit 951086f

Please sign in to comment.