From deb676afb3e1570ed4e2a7d536597898555ffff6 Mon Sep 17 00:00:00 2001 From: pkulik0 Date: Thu, 13 Jun 2024 13:12:22 +0000 Subject: [PATCH] Add test cases for ToJAASTag, make the way fetchRelations returns tuples clearer --- cmd/jimmctl/cmd/relation.go | 3 +-- internal/jujuapi/access_control_test.go | 10 +++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/jimmctl/cmd/relation.go b/cmd/jimmctl/cmd/relation.go index 9435c06d9..554a4a670 100644 --- a/cmd/jimmctl/cmd/relation.go +++ b/cmd/jimmctl/cmd/relation.go @@ -569,8 +569,7 @@ func fetchRelations(client *api.Client, params apiparams.ListRelationshipTuplesR tuples = append(tuples, response.Tuples...) if response.ContinuationToken == "" { - response.Tuples = tuples - return response, nil + return &apiparams.ListRelationshipTuplesResponse{Tuples: tuples, Errors: response.Errors}, nil } params.ContinuationToken = response.ContinuationToken } diff --git a/internal/jujuapi/access_control_test.go b/internal/jujuapi/access_control_test.go index b5327f9af..074951ddc 100644 --- a/internal/jujuapi/access_control_test.go +++ b/internal/jujuapi/access_control_test.go @@ -22,6 +22,7 @@ import ( "github.com/canonical/jimm/internal/jujuapi" "github.com/canonical/jimm/internal/openfga" ofganames "github.com/canonical/jimm/internal/openfga/names" + "github.com/canonical/jimm/pkg/names" ) type accessControlSuite struct { @@ -792,7 +793,8 @@ func (s *accessControlSuite) TestJAASTag(c *gc.C) { ctx := context.Background() db := s.JIMM.Database - user, _, controller, model, applicationOffer, cloud, _, _, closeClient := createTestControllerEnvironment(ctx, c, s) + user, group, controller, model, applicationOffer, cloud, _, _, closeClient := createTestControllerEnvironment(ctx, c, s) + serviceAccountId := petname.Generate(2, "-") + "@serviceaccount" closeClient() tests := []struct { @@ -802,6 +804,12 @@ func (s *accessControlSuite) TestJAASTag(c *gc.C) { }{{ tag: ofganames.ConvertTag(user.ResourceTag()), expectedJAASTag: "user-" + user.Name, + }, { + tag: ofganames.ConvertTag(names.NewServiceAccountTag(serviceAccountId)), + expectedJAASTag: "serviceaccount-" + serviceAccountId, + }, { + tag: ofganames.ConvertTag(group.ResourceTag()), + expectedJAASTag: "group-" + group.Name, }, { tag: ofganames.ConvertTag(controller.ResourceTag()), expectedJAASTag: "controller-" + controller.Name,