Skip to content

Commit

Permalink
fix: separate admin email and system email in test
Browse files Browse the repository at this point in the history
  • Loading branch information
FemiNoviaLina committed Apr 17, 2024
1 parent cb98d9e commit eeaaad7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion test/e2e_test/regression/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ func (s *EndToEndAPIRegressionTestSuite) SetupTest() {
s.client, s.appConfig, s.cancelClient, _ = testbench.SetupTests(s.T())

// validate
// list user length is 10 because there are 8 mock data, 1 system email, and 1 admin email created in test setup
uRes, err := s.client.ListUsers(ctx, &shieldv1beta1.ListUsersRequest{})
s.Require().NoError(err)
s.Require().Equal(9, len(uRes.GetUsers()))
s.Require().Equal(10, len(uRes.GetUsers()))

oRes, err := s.client.ListOrganizations(ctx, &shieldv1beta1.ListOrganizationsRequest{})
s.Require().NoError(err)
Expand Down
3 changes: 2 additions & 1 deletion test/e2e_test/smoke/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ func (s *EndToEndAPISmokeTestSuite) SetupTest() {
s.client, s.appConfig, s.cancelClient, _ = testbench.SetupTests(s.T())

// validate
// list user length is 10 because there are 8 mock data, 1 system email, and 1 admin email created in test setup
uRes, err := s.client.ListUsers(ctx, &shieldv1beta1.ListUsersRequest{})
s.Require().NoError(err)
s.Require().Equal(9, len(uRes.GetUsers()))
s.Require().Equal(10, len(uRes.GetUsers()))
s.users = uRes.GetUsers()

oRes, err := s.client.ListOrganizations(ctx, &shieldv1beta1.ListOrganizationsRequest{})
Expand Down
3 changes: 2 additions & 1 deletion test/e2e_test/smoke/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ func (s *EndToEndProxySmokeTestSuite) SetupTest() {
s.dbClient = dbClient

// validate
// list user length is 10 because there are 8 mock data, 1 system email, and 1 admin email created in test setup
uRes, err := s.client.ListUsers(ctx, &shieldv1beta1.ListUsersRequest{})
s.Require().NoError(err)
s.Require().Equal(9, len(uRes.GetUsers()))
s.Require().Equal(10, len(uRes.GetUsers()))
s.userID = uRes.GetUsers()[0].GetId()

oRes, err := s.client.ListOrganizations(ctx, &shieldv1beta1.ListOrganizationsRequest{})
Expand Down
7 changes: 4 additions & 3 deletions test/e2e_test/testbench/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
)

const (
OrgAdminEmail = "[email protected]"
IdentityHeader = "X-Shield-Email"
userIDHeaderKey = "X-Shield-UserID"
OrgAdminEmail = "[email protected]"
DefaultSystemEmail = "[email protected]"
IdentityHeader = "X-Shield-Email"
userIDHeaderKey = "X-Shield-UserID"
)

func GetFreePort() (int, error) {
Expand Down
15 changes: 14 additions & 1 deletion test/e2e_test/testbench/testbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
shieldv1beta1 "github.com/goto/shield/proto/v1beta1"
"github.com/ory/dockertest"
"github.com/ory/dockertest/docker"
"google.golang.org/grpc/metadata"
)

const (
Expand Down Expand Up @@ -198,7 +199,7 @@ func SetupTests(t *testing.T) (shieldv1beta1.ShieldServiceClient, *config.Shield
GRPC: server.GRPCConfig{
Port: apiGRPCPort,
},
DefaultSystemEmail: OrgAdminEmail,
DefaultSystemEmail: DefaultSystemEmail,
IdentityProxyHeader: IdentityHeader,
UserIDHeader: userIDHeaderKey,
ResourcesConfigPath: fmt.Sprintf("file://%s/%s", testDataPath, "configs/resources"),
Expand Down Expand Up @@ -228,6 +229,18 @@ func SetupTests(t *testing.T) (shieldv1beta1.ShieldServiceClient, *config.Shield
t.Fatal(err)
}

ctx = metadata.NewOutgoingContext(ctx, metadata.New(map[string]string{
IdentityHeader: DefaultSystemEmail,
}))
if _, err := client.CreateUser(ctx, &shieldv1beta1.CreateUserRequest{
Body: &shieldv1beta1.UserRequestBody{
Name: OrgAdminEmail,
Email: OrgAdminEmail,
},
}); err != nil {
t.Fatal(err.Error())
}

if err := BootstrapMetadataKey(ctx, client, OrgAdminEmail, testDataPath); err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit eeaaad7

Please sign in to comment.