Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

add e2e tests

Thiago Araujo da Silvadf4c7cd5b2de
diff --git a/tests/fixture/sso/oidc.go b/tests/fixture/sso/oidc.go
index 64f0715622..b3668f6299 100644
--- a/tests/fixture/sso/oidc.go
+++ b/tests/fixture/sso/oidc.go
@@ -112,6 +112,16 @@ func (o *OIDC) Session(tt *testing.T, res *api.OidcCallbackResponse) *api.Client
return Session(tt, o.Tenant, res.HTTPResponse)
}
+// SignedUp logs a new person in through OIDC and completes their signup, leaving an
+// accepted member with a verified OIDC account.
+func (o *OIDC) SignedUp(tt *testing.T) oidcidp.Person {
+ tt.Helper()
+ person := o.Person()
+ res := o.CompleteSignup(tt, o.Login(tt, person), VerificationCode(tt, o.Tenant, person.Email))
+ require.Equalf(tt, http.StatusOK, res.StatusCode(), "completing SSO signup: %s", apierr.Body(res.Body))
+ return person
+}
+
func (o *OIDC) CompleteSignup(tt *testing.T, res *api.OidcCallbackResponse, code string) *api.CompleteAccountSignupV3Response {
tt.Helper()
o.Redirect(tt, res)
diff --git a/tests/suites/sso/oidc/enforcement_test.go b/tests/suites/sso/oidc/enforcement_test.go
index 1128ce7fee..b854fe4982 100644
--- a/tests/suites/sso/oidc/enforcement_test.go
+++ b/tests/suites/sso/oidc/enforcement_test.go
@@ -36,7 +36,7 @@ func TestOIDCEnforcement(t *testing.T) {
// Setup
o := setup(t)
- signedUp(t, o)
+ o.SignedUp(t)
// Action
res, err := o.Tenant.Admin.API.UpdateOrganizationWithResponse(t.Context(), o.Tenant.OrgID.String(),
@@ -94,7 +94,7 @@ func TestOIDCEnforcement(t *testing.T) {
// Setup
o := setup(t)
- alice := signedUp(t, o)
+ alice := o.SignedUp(t)
sso.Enforce(t, o.Tenant)
session := o.Session(t, o.Login(t, alice))
diff --git a/tests/suites/sso/oidc/helpers_test.go b/tests/suites/sso/oidc/helpers_test.go
index 18000170a3..5871913183 100644
--- a/tests/suites/sso/oidc/helpers_test.go
+++ b/tests/suites/sso/oidc/helpers_test.go
@@ -7,7 +7,6 @@ import (
"testing"
"github.com/Infisical/infisical/tests/clients/api"
- "github.com/Infisical/infisical/tests/fakes/oidcidp"
"github.com/Infisical/infisical/tests/fixture/sso"
"github.com/Infisical/infisical/tests/harness"
"github.com/Infisical/infisical/tests/internal/apierr"
@@ -19,21 +18,10 @@ func setup(t *testing.T) *sso.OIDC {
return sso.NewOIDC(t, harness.From(t).NewTenant(t))
}
-// signedUp logs a new person in through OIDC and completes their signup, leaving an
-// accepted member with a verified OIDC account.
-func signedUp(t *testing.T, o *sso.OIDC) oidcidp.Person {
- t.Helper()
- person := o.Person()
- login := o.Login(t, person)
- res := o.CompleteSignup(t, login, sso.VerificationCode(t, o.Tenant, person.Email))
- require.Equalf(t, http.StatusOK, res.StatusCode(), "completing SSO signup: %s", apierr.Body(res.Body))
- return person
-}
-
// enforce makes OIDC the org's required login, which needs one OIDC login first.
func enforce(t *testing.T, o *sso.OIDC) {
t.Helper()
- signedUp(t, o)
+ o.SignedUp(t)
sso.Enforce(t, o.Tenant)
}
diff --git a/tests/suites/sso/oidc/login_test.go b/tests/suites/sso/oidc/login_test.go
index 1fa141c22c..d52b8dbfea 100644
--- a/tests/suites/sso/oidc/login_test.go
+++ b/tests/suites/sso/oidc/login_test.go
@@ -103,7 +103,7 @@ func TestOIDCLogin_ReturningUser(t *testing.T) {
// Setup
o := setup(t)
- alice := signedUp(t, o)
+ alice := o.SignedUp(t)
// Action
res := o.Login(t, alice)
@@ -122,7 +122,7 @@ func TestOIDCLogin_ReturningUser(t *testing.T) {
// Setup
o := setup(t)
- alice := signedUp(t, o)
+ alice := o.SignedUp(t)
m := fixture.MembershipOf(t, o.Tenant, alice.Email)
deactivated, err := o.Tenant.Admin.API.UpdateOrgMembershipWithResponse(t.Context(), o.Tenant.OrgID.String(), m.ID.String(),
api.UpdateOrgMembershipJSONRequestBody{IsActive: new(false)})
diff --git a/tests/suites/sso/oidc/mfatrust_test.go b/tests/suites/sso/oidc/mfatrust_test.go
index 3b6a6df6c6..7b0d32c4cc 100644
--- a/tests/suites/sso/oidc/mfatrust_test.go
+++ b/tests/suites/sso/oidc/mfatrust_test.go
@@ -44,7 +44,7 @@ func TestOIDCMFATrust(t *testing.T) {
// Setup
o := setup(t)
- alice := signedUp(t, o)
+ alice := o.SignedUp(t)
sso.EnforceMFA(t, o.Tenant, api.Signal)
if c.config != nil {
updateConfig(t, o, *c.config)
diff --git a/tests/suites/sso/sessionbinding/helpers_test.go b/tests/suites/sso/sessionbinding/helpers_test.go
new file mode 100644
index 0000000000..8dcd4df343
--- /dev/null
+++ b/tests/suites/sso/sessionbinding/helpers_test.go
@@ -0,0 +1,131 @@
+package sessionbinding_test
+
+import (
+ "context"
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/Infisical/infisical/tests/clients/api"
+ "github.com/Infisical/infisical/tests/fixture/sso"
+ "github.com/Infisical/infisical/tests/harness"
+ "github.com/Infisical/infisical/tests/internal/apierr"
+ "github.com/Infisical/infisical/tests/internal/wait"
+ "github.com/google/uuid"
+ openapi_types "github.com/oapi-codegen/runtime/types"
+ "github.com/stretchr/testify/require"
+)
+
+// The org whose IdP logs alice in. Any other org she's in didn't issue her session.
+type issuer struct {
+ tn *harness.Tenant
+ email string
+ login func(t *testing.T) *http.Response
+}
+
+func samlIssuer(t *testing.T) issuer {
+ t.Helper()
+ s := sso.NewSAML(t, harness.From(t).NewTenant(t), sso.Okta)
+ alice := s.SignedUp(t)
+ return issuer{tn: s.Tenant, email: alice.Email, login: func(t *testing.T) *http.Response {
+ t.Helper()
+ acs := s.SPLogin(t, alice)
+ s.Redirect(t, acs)
+ return acs.HTTPResponse
+ }}
+}
+
+func oidcIssuer(t *testing.T) issuer {
+ t.Helper()
+ o := sso.NewOIDC(t, harness.From(t).NewTenant(t))
+ alice := o.SignedUp(t)
+ return issuer{tn: o.Tenant, email: alice.Email, login: func(t *testing.T) *http.Response {
+ t.Helper()
+ res := o.Login(t, alice)
+ o.Redirect(t, res)
+ return res.HTTPResponse
+ }}
+}
+
+func (iss issuer) selectOrg(t *testing.T, login *http.Response, orgID uuid.UUID) *api.SelectOrganizationV3Response {
+ t.Helper()
+ return sso.SelectOrganization(t, iss.tn, login, orgID.String())
+}
+
+// Returns the response too, its jid cookie keeps the session going.
+func (iss issuer) session(t *testing.T, login *http.Response, orgID uuid.UUID) (*api.ClientWithResponses, *http.Response) {
+ t.Helper()
+ res := iss.selectOrg(t, login, orgID)
+ require.Equalf(t, http.StatusOK, res.StatusCode(), "selecting %s: %s", orgID, apierr.Body(res.Body))
+ require.False(t, res.JSON200.IsMfaEnabled, "selecting the org asked for MFA")
+ return iss.tn.Client(t, res.JSON200.Token), res.HTTPResponse
+}
+
+// alice signs in through iss and is also in other with role. other has its own SAML so
+// it can turn on enforcement.
+func setup(t *testing.T, role string) (issuer, *sso.SAML) {
+ t.Helper()
+ return setupWith(t, samlIssuer, role)
+}
+
+func setupWith(t *testing.T, newIssuer func(*testing.T) issuer, role string) (issuer, *sso.SAML) {
+ t.Helper()
+ iss := newIssuer(t)
+ other := sso.NewSAML(t, harness.From(t).NewTenant(t), sso.Okta)
+ join(t, other.Tenant.Admin.API, other.Tenant.OrgID, iss.email, role)
+ return iss, other
+}
+
+// admin needs a session scoped to orgID.
+func join(t *testing.T, admin *api.ClientWithResponses, orgID uuid.UUID, email, role string) {
+ t.Helper()
+ res, err := admin.InviteUsersToOrganizationWithResponse(t.Context(), api.InviteUsersToOrganizationJSONRequestBody{
+ InviteeEmails: []openapi_types.Email{openapi_types.Email(email)},
+ OrganizationId: orgID.String(),
+ OrganizationRoleSlug: &role,
+ })
+ require.NoError(t, err)
+ require.Equalf(t, http.StatusOK, res.StatusCode(), "inviting %s: %s", email, apierr.Body(res.Body))
+}
+
+func readOrg(t *testing.T, c *api.ClientWithResponses, orgID uuid.UUID) (int, []byte) {
+ t.Helper()
+ res, err := c.GetOrganizationByIdWithResponse(t.Context(), orgID.String())
+ require.NoError(t, err)
+ return res.StatusCode(), res.Body
+}
+
+func readProject(t *testing.T, c *api.ClientWithResponses, projectID string) (int, []byte) {
+ t.Helper()
+ res, err := c.GetProjectByIdWithResponse(t.Context(), projectID)
+ require.NoError(t, err)
+ return res.StatusCode(), res.Body
+}
+
+func requireForeignSession(t *testing.T, status int, body []byte) {
+ t.Helper()
+ require.Equalf(t, http.StatusForbidden, status, "%s", apierr.Body(body))
+ require.Contains(t, string(body), "another organization's identity provider")
+}
+
+// Audit logs go through a queue, so poll.
+func waitForAuditEvent(t *testing.T, tn *harness.Tenant, eventType string, match func(map[string]any) bool) map[string]any {
+ t.Helper()
+ got, err := wait.For(t.Context(), func(ctx context.Context) (map[string]any, bool, error) {
+ res, err := tn.Admin.API.ListOrganizationAuditLogsWithResponse(ctx, &api.ListOrganizationAuditLogsParams{
+ EventType: &eventType,
+ StartDate: new(time.Now().UTC().Add(-time.Hour).Truncate(time.Second)),
+ })
+ if err != nil || res.JSON200 == nil {
+ return nil, false, err
+ }
+ for _, l := range res.JSON200.AuditLogs {
+ if m, ok := l.Event.Metadata.(map[string]any); ok && match(m) {
+ return m, true, nil
+ }
+ }
+ return nil, false, nil
+ })
+ require.NoErrorf(t, err, "waiting for a %s audit event", eventType)
+ return got
+}
diff --git a/tests/suites/sso/sessionbinding/main_test.go b/tests/suites/sso/sessionbinding/main_test.go
new file mode 100644
index 0000000000..4e58f2abd6
--- /dev/null
+++ b/tests/suites/sso/sessionbinding/main_test.go
@@ -0,0 +1,9 @@
+package sessionbinding_test
+
+import (
+ "testing"
+
+ "github.com/Infisical/infisical/tests/harness"
+)
+
+func TestMain(m *testing.M) { harness.Main(m, harness.Shared) }
diff --git a/tests/suites/sso/sessionbinding/opensession_test.go b/tests/suites/sso/sessionbinding/opensession_test.go
new file mode 100644
index 0000000000..9928c16264
--- /dev/null
+++ b/tests/suites/sso/sessionbinding/opensession_test.go
@@ -0,0 +1,53 @@
+package sessionbinding_test
+
+import (
+ "net/http"
+ "testing"
+
+ "github.com/Infisical/infisical/tests/fixture"
+ "github.com/Infisical/infisical/tests/harness"
+ "github.com/Infisical/infisical/tests/internal/apierr"
+ "github.com/Infisical/infisical/tests/internal/spec"
+ "github.com/stretchr/testify/require"
+)
+
+func TestSessionBinding_OpenSession(t *testing.T) {
+ t.Parallel()
+
+ t.Run("should refuse org resources on the next request once the org starts enforcing SSO", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ iss, other := setup(t, "member")
+ alice, _ := iss.session(t, iss.login(t), other.Tenant.OrgID)
+ status, body := readOrg(t, alice, other.Tenant.OrgID)
+ require.Equalf(t, http.StatusOK, status, "reading the org before enforcement: %s", apierr.Body(body))
+ other.Enforce(t)
+
+ // Action
+ status, body = readOrg(t, alice, other.Tenant.OrgID)
+
+ // Assert
+ requireForeignSession(t, status, body)
+ })
+
+ t.Run("should refuse a project read on the next request once the org starts enforcing SSO", func(t *testing.T) {
+ t.Parallel()
+ spec.Why(t, "the first read caches the project permission, enforcement can't wait for it to expire")
+
+ // Setup
+ iss, other := setup(t, "member")
+ proj := fixture.NewProject(t, other.Tenant, fixture.WithProjectType("secret-manager"))
+ proj.Grant(t, &harness.Principal{Kind: harness.User, Email: iss.email})
+ alice, _ := iss.session(t, iss.login(t), other.Tenant.OrgID)
+ status, body := readProject(t, alice, proj.ID)
+ require.Equalf(t, http.StatusOK, status, "reading the project before enforcement: %s", apierr.Body(body))
+ other.Enforce(t)
+
+ // Action
+ status, body = readProject(t, alice, proj.ID)
+
+ // Assert
+ requireForeignSession(t, status, body)
+ })
+}
diff --git a/tests/suites/sso/sessionbinding/reissue_test.go b/tests/suites/sso/sessionbinding/reissue_test.go
new file mode 100644
index 0000000000..ab7d80a4ad
--- /dev/null
+++ b/tests/suites/sso/sessionbinding/reissue_test.go
@@ -0,0 +1,88 @@
+package sessionbinding_test
+
+import (
+ "net/http"
+ "testing"
+
+ "github.com/Infisical/infisical/tests/clients/api"
+ "github.com/Infisical/infisical/tests/fakes/smtp"
+ "github.com/Infisical/infisical/tests/fixture/sso"
+ "github.com/Infisical/infisical/tests/harness"
+ "github.com/Infisical/infisical/tests/internal/apierr"
+ "github.com/Infisical/infisical/tests/internal/id"
+ "github.com/Infisical/infisical/tests/internal/mail"
+ "github.com/stretchr/testify/require"
+)
+
+// Any path that mints a new session from an old one has to keep the issuer. Drop it and
+// the session passes every org's enforcement, so each case ends at an enforcing org.
+func TestSessionBinding_Reissue(t *testing.T) {
+ t.Parallel()
+
+ t.Run("should keep refusing the session after it passes the issuing org's MFA challenge", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ iss, other := setup(t, "member")
+ other.Enforce(t)
+ sso.EnforceMFA(t, iss.tn, api.None)
+ challenge := iss.selectOrg(t, iss.login(t), iss.tn.OrgID)
+ require.Equalf(t, http.StatusOK, challenge.StatusCode(), "selecting the issuing org: %s", apierr.Body(challenge.Body))
+ require.True(t, challenge.JSON200.IsMfaEnabled, "the issuing org didn't ask for MFA")
+ code, err := mail.Code(iss.tn.Mail(t).Expect(t, iss.email, smtp.Subject("Infisical MFA code")), 6)
+ require.NoError(t, err)
+ verified, err := iss.tn.Client(t, challenge.JSON200.Token).VerifyMfaWithResponse(t.Context(), api.VerifyMfaJSONRequestBody{MfaToken: code})
+ require.NoError(t, err)
+ require.Equalf(t, http.StatusOK, verified.StatusCode(), "verifying MFA: %s", apierr.Body(verified.Body))
+
+ // Action
+ res := iss.selectOrg(t, verified.HTTPResponse, other.Tenant.OrgID)
+
+ // Assert
+ requireForeignSession(t, res.StatusCode(), res.Body)
+ })
+
+ t.Run("should refuse the session a first SSO login mints when it verifies the mailbox", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ s := sso.NewSAML(t, harness.From(t).NewTenant(t), sso.Okta)
+ other := sso.NewSAML(t, harness.From(t).NewTenant(t), sso.Okta)
+ alice := s.Person()
+ join(t, other.Tenant.Admin.API, other.Tenant.OrgID, alice.Email, "member")
+ other.Enforce(t)
+ signup := s.CompleteSignup(t, s.SPLogin(t, alice), s.VerificationCode(t, alice.Email))
+ require.Equalf(t, http.StatusOK, signup.StatusCode(), "completing SSO signup: %s", apierr.Body(signup.Body))
+
+ // Action
+ res, err := s.Tenant.Client(t, signup.JSON200.Token).SelectOrganizationV3WithResponse(t.Context(),
+ api.SelectOrganizationV3JSONRequestBody{OrganizationId: other.Tenant.OrgID.String()})
+
+ // Assert
+ require.NoError(t, err)
+ requireForeignSession(t, res.StatusCode(), res.Body)
+ })
+
+ t.Run("should keep refusing the session re-issued when the user deletes an org", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ iss, other := setup(t, "member")
+ other.Enforce(t)
+ alice, selected := iss.session(t, iss.login(t), iss.tn.OrgID)
+ created, err := alice.CreateOrganizationWithResponse(t.Context(), api.CreateOrganizationJSONRequestBody{Name: "throwaway-" + id.Short()})
+ require.NoError(t, err)
+ require.NotNilf(t, created.JSON200, "creating an org returned %d: %s", created.StatusCode(), apierr.Body(created.Body))
+ throwawayID := created.JSON200.Organization.Id
+ inThrowaway, _ := iss.session(t, selected, throwawayID)
+ deleted, err := inThrowaway.DeleteOrganizationWithResponse(t.Context(), throwawayID.String())
+ require.NoError(t, err)
+ require.Equalf(t, http.StatusOK, deleted.StatusCode(), "deleting the org: %s", apierr.Body(deleted.Body))
+
+ // Action
+ res := iss.selectOrg(t, deleted.HTTPResponse, other.Tenant.OrgID)
+
+ // Assert
+ requireForeignSession(t, res.StatusCode(), res.Body)
+ })
+}
diff --git a/tests/suites/sso/sessionbinding/selection_test.go b/tests/suites/sso/sessionbinding/selection_test.go
new file mode 100644
index 0000000000..0d27546c43
--- /dev/null
+++ b/tests/suites/sso/sessionbinding/selection_test.go
@@ -0,0 +1,84 @@
+package sessionbinding_test
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ "github.com/Infisical/infisical/tests/fakes/smtp"
+ "github.com/Infisical/infisical/tests/internal/apierr"
+ "github.com/stretchr/testify/require"
+)
+
+func TestSessionBinding_SelectOrganization(t *testing.T) {
+ t.Parallel()
+
+ issuers := []struct {
+ name string
+ new func(*testing.T) issuer
+ }{
+ {"SAML", samlIssuer},
+ {"OIDC", oidcIssuer},
+ }
+ for _, i := range issuers {
+ t.Run("should refuse selection when the org enforces SSO and another org's "+i.name+" IdP issued the session", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ iss, other := setupWith(t, i.new, "member")
+ other.Enforce(t)
+
+ // Action
+ res := iss.selectOrg(t, iss.login(t), other.Tenant.OrgID)
+
+ // Assert
+ requireForeignSession(t, res.StatusCode(), res.Body)
+ })
+ }
+
+ t.Run("should audit the refusal in the refusing org without naming the issuing org", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ iss, other := setup(t, "member")
+ other.Enforce(t)
+
+ // Action
+ iss.selectOrg(t, iss.login(t), other.Tenant.OrgID)
+
+ // Assert
+ refused := waitForAuditEvent(t, other.Tenant, "select-organization-refused", func(m map[string]any) bool {
+ return m["organizationId"] == other.Tenant.OrgID.String()
+ })
+ require.NotContains(t, fmt.Sprint(refused), iss.tn.OrgID.String())
+ })
+
+ t.Run("should admit a session another org's IdP issued when the org does not enforce SSO", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ iss, other := setup(t, "member")
+
+ // Action
+ res := iss.selectOrg(t, iss.login(t), other.Tenant.OrgID)
+
+ // Assert
+ require.Equalf(t, http.StatusOK, res.StatusCode(), "%s", apierr.Body(res.Body))
+ })
+
+ t.Run("should let a member who can bypass SSO through as break-glass and alert the org's admins", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ iss, other := setup(t, "admin")
+ other.Enforce(t)
+
+ // Action
+ res := iss.selectOrg(t, iss.login(t), other.Tenant.OrgID)
+
+ // Assert
+ require.Equalf(t, http.StatusOK, res.StatusCode(), "%s", apierr.Body(res.Body))
+ alert := other.Tenant.Mail(t).Expect(t, other.Tenant.Admin.Email, smtp.Subject("SSO Bypass"))
+ require.Contains(t, alert.Body, iss.email)
+ })
+}
diff --git a/tests/suites/sso/sessionbinding/suborg_test.go b/tests/suites/sso/sessionbinding/suborg_test.go
new file mode 100644
index 0000000000..ad38dc906c
--- /dev/null
+++ b/tests/suites/sso/sessionbinding/suborg_test.go
@@ -0,0 +1,82 @@
+package sessionbinding_test
+
+import (
+ "net/http"
+ "testing"
+
+ "github.com/Infisical/infisical/tests/clients/api"
+ "github.com/Infisical/infisical/tests/fixture"
+ "github.com/Infisical/infisical/tests/internal/apierr"
+ "github.com/Infisical/infisical/tests/internal/id"
+ "github.com/Infisical/infisical/tests/internal/spec"
+ "github.com/stretchr/testify/require"
+)
+
+func TestSessionBinding_SubOrganization(t *testing.T) {
+ t.Parallel()
+
+ t.Run("should refuse a sub-org session on the next request once the root org starts enforcing SSO", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ iss, other := setup(t, "member")
+ sub := fixture.NewSubOrg(t, other.Tenant)
+ join(t, sub.Admin.API, sub.ID, iss.email, "member")
+ alice, _ := iss.session(t, iss.login(t), sub.ID)
+ status, body := readOrg(t, alice, sub.ID)
+ require.Equalf(t, http.StatusOK, status, "reading the sub-org before enforcement: %s", apierr.Body(body))
+ other.Enforce(t)
+
+ // Action
+ status, body = readOrg(t, alice, sub.ID)
+
+ // Assert
+ requireForeignSession(t, status, body)
+ })
+
+ t.Run("should refuse a sub-org admin when the root org allows bypass, only a root org role bypasses", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ iss, other := setup(t, "member")
+ sub := fixture.NewSubOrg(t, other.Tenant)
+ join(t, sub.Admin.API, sub.ID, iss.email, "admin")
+ alice, _ := iss.session(t, iss.login(t), sub.ID)
+ other.Enforce(t)
+
+ // Action
+ status, body := readOrg(t, alice, sub.ID)
+
+ // Assert
+ requireForeignSession(t, status, body)
+ })
+
+ t.Run("should refuse a sub-org project read on the next request once the root org admin role is revoked", func(t *testing.T) {
+ t.Parallel()
+ spec.Why(t, "the sub-org project's cached permission doesn't track root org roles")
+
+ // Setup
+ iss, other := setup(t, "admin")
+ sub := fixture.NewSubOrg(t, other.Tenant)
+ join(t, sub.Admin.API, sub.ID, iss.email, "admin")
+ alice, _ := iss.session(t, iss.login(t), sub.ID)
+ kind := api.CreateProjectJSONBodyType("secret-manager")
+ created, err := alice.CreateProjectWithResponse(t.Context(), api.CreateProjectJSONRequestBody{ProjectName: "p-" + id.Short(), Type: &kind})
+ require.NoError(t, err)
+ require.NotNilf(t, created.JSON200, "creating a project returned %d: %s", created.StatusCode(), apierr.Body(created.Body))
+ projectID := created.JSON200.Project.Id
+ other.Enforce(t)
+ status, body := readProject(t, alice, projectID)
+ require.Equalf(t, http.StatusOK, status, "reading the project as a root org admin: %s", apierr.Body(body))
+ demoted, err := other.Tenant.Admin.API.UpdateOrgMembershipWithResponse(t.Context(), other.Tenant.OrgID.String(),
+ fixture.MembershipOf(t, other.Tenant, iss.email).ID.String(), api.UpdateOrgMembershipJSONRequestBody{Role: new("member")})
+ require.NoError(t, err)
+ require.Equalf(t, http.StatusOK, demoted.StatusCode(), "demoting to member: %s", apierr.Body(demoted.Body))
+
+ // Action
+ status, body = readProject(t, alice, projectID)
+
+ // Assert
+ requireForeignSession(t, status, body)
+ })
+}