Skip to content

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

tests: machine identity, group, sub-org, audit log, alert and gateway suites

Claude8da2a2246daa
diff --git a/tests/suites/admin/admin_test.go b/tests/suites/admin/admin_test.go
index d321be0bcb..2ebb63c821 100644
--- a/tests/suites/admin/admin_test.go
+++ b/tests/suites/admin/admin_test.go
@@ -238,36 +238,45 @@ func setConfig(t *testing.T, admin *harness.Principal, body api.UpdateAdminConfi
})
}
-// setLoginMethods writes the enabled login methods as a user server admin who can
-// also sign in with Google, so the lockout guard lets email be switched off. The
-// machine identity instance admin cannot do it (see TestAdminConfig_KnownIssues).
+// setLoginMethods writes the enabled login methods as the root user, after letting it
+// sign in with Google too so the lockout guard allows email to be switched off. The
+// machine identity instance admin cannot write them (see TestAdminConfig_KnownIssues),
+// and granting server admin to another user needs an instance license.
func setLoginMethods(t *testing.T, h *harness.Stack, methods ...api.UpdateAdminConfigJSONBodyEnabledLoginMethods) {
t.Helper()
- setConfig(t, userServerAdmin(t, h), api.UpdateAdminConfigJSONRequestBody{EnabledLoginMethods: &methods})
+ setConfig(t, rootUser(t, h), api.UpdateAdminConfigJSONRequestBody{EnabledLoginMethods: &methods})
}
-// userServerAdmin is a user in its own tenant, granted server admin for the test.
-func userServerAdmin(t *testing.T, h *harness.Stack) *harness.Principal {
+func rootUser(t *testing.T, h *harness.Stack) *harness.Principal {
t.Helper()
- admin := h.InstanceAdmin(t)
- operator := h.NewTenant(t).Admin
-
- methods, err := operator.API.UpdateUserAuthMethodsWithResponse(t.Context(), api.UpdateUserAuthMethodsJSONRequestBody{
- AuthMethods: []api.UpdateUserAuthMethodsJSONBodyAuthMethods{
- api.UpdateUserAuthMethodsJSONBodyAuthMethodsEmail,
- api.UpdateUserAuthMethodsJSONBodyAuthMethodsGoogle,
- },
- })
+ tn := h.NewTenant(t)
+ res, err := tn.Anonymous(t, infisical.ForwardedFor(sourceIP())).LoginV3WithResponse(t.Context(),
+ api.LoginV3JSONRequestBody{Email: infisical.RootEmail, Password: infisical.RootPassword})
require.NoError(t, err)
- requireStatus(t, http.StatusOK, methods.StatusCode(), methods.Body)
-
- granted, err := admin.API.GrantAdminAccessToUserWithResponse(t.Context(), operator.ID.String())
+ requireStatus(t, http.StatusOK, res.StatusCode(), res.Body)
+ ip := sourceIP()
+ unscoped := tn.Client(t, res.JSON200.AccessToken, infisical.ForwardedFor(ip))
+ orgs, err := unscoped.ListUserOrganizationsWithResponse(t.Context())
+ require.NoError(t, err)
+ requireStatus(t, http.StatusOK, orgs.StatusCode(), orgs.Body)
+ require.NotEmpty(t, orgs.JSON200.Organizations)
+ selected, err := unscoped.SelectOrganizationV3WithResponse(t.Context(),
+ api.SelectOrganizationV3JSONRequestBody{OrganizationId: orgs.JSON200.Organizations[0].Id.String()})
require.NoError(t, err)
- requireStatus(t, http.StatusOK, granted.StatusCode(), granted.Body)
+ requireStatus(t, http.StatusOK, selected.StatusCode(), selected.Body)
+ root := &harness.Principal{Kind: harness.User, Email: infisical.RootEmail, Token: selected.JSON200.Token}
+ root.API = tn.Client(t, root.Token, infisical.ForwardedFor(ip))
+
+ setAuthMethods := func(ctx context.Context, methods ...api.UpdateUserAuthMethodsJSONBodyAuthMethods) {
+ res, err := root.API.UpdateUserAuthMethodsWithResponse(ctx, api.UpdateUserAuthMethodsJSONRequestBody{AuthMethods: methods})
+ require.NoError(t, err)
+ requireStatus(t, http.StatusOK, res.StatusCode(), res.Body)
+ }
+ setAuthMethods(t.Context(), api.UpdateUserAuthMethodsJSONBodyAuthMethodsEmail, api.UpdateUserAuthMethodsJSONBodyAuthMethodsGoogle)
t.Cleanup(func() {
- _, _ = admin.API.RevokeAdminAccessFromUserWithResponse(context.WithoutCancel(t.Context()), operator.ID.String())
+ setAuthMethods(context.WithoutCancel(t.Context()), api.UpdateUserAuthMethodsJSONBodyAuthMethodsEmail)
})
- return operator
+ return root
}
func allLoginMethods() []api.UpdateAdminConfigJSONBodyEnabledLoginMethods {
diff --git a/tests/suites/group/helpers_test.go b/tests/suites/group/helpers_test.go
index da76f41f73..726f8e9689 100644
--- a/tests/suites/group/helpers_test.go
+++ b/tests/suites/group/helpers_test.go
@@ -217,4 +217,3 @@ func groupUsernames(t *testing.T, tn *harness.Tenant, groupID uuid.UUID) []strin
}
return out
}
-
diff --git a/tests/suites/group/project_test.go b/tests/suites/group/project_test.go
index 0b30aaa931..7f2c0d2ddf 100644
--- a/tests/suites/group/project_test.go
+++ b/tests/suites/group/project_test.go
@@ -120,6 +120,7 @@ func TestGroup_Project(t *testing.T) {
projectID := sub.NewProject(t)
// Action
+ //lint:ignore SA1019 the deprecated route is the only one that resolves a group by name
res, err := sub.Admin.API.AddGroupToProjectWithBodyWithResponse(t.Context(), projectID, rootGroup.Name,
"application/json", jsonBody(t, map[string]any{"role": "viewer"}))
diff --git a/tests/suites/machineidentityfed/alicloudauth_test.go b/tests/suites/machineidentity/alicloudauth_test.go
similarity index 99%
rename from tests/suites/machineidentityfed/alicloudauth_test.go
rename to tests/suites/machineidentity/alicloudauth_test.go
index aaf72e3e91..4c18b2cd6a 100644
--- a/tests/suites/machineidentityfed/alicloudauth_test.go
+++ b/tests/suites/machineidentity/alicloudauth_test.go
@@ -1,4 +1,4 @@
-package machineidentityfed_test
+package machineidentity_test
import (
"net/http"
diff --git a/tests/suites/machineidentityfed/awsauth_test.go b/tests/suites/machineidentity/awsauth_test.go
similarity index 99%
rename from tests/suites/machineidentityfed/awsauth_test.go
rename to tests/suites/machineidentity/awsauth_test.go
index f644801978..9eb3d78c1d 100644
--- a/tests/suites/machineidentityfed/awsauth_test.go
+++ b/tests/suites/machineidentity/awsauth_test.go
@@ -1,4 +1,4 @@
-package machineidentityfed_test
+package machineidentity_test
import (
"crypto/hmac"
diff --git a/tests/suites/machineidentityfed/azureauth_test.go b/tests/suites/machineidentity/azureauth_test.go
similarity index 99%
rename from tests/suites/machineidentityfed/azureauth_test.go
rename to tests/suites/machineidentity/azureauth_test.go
index c3914fa494..c6b65ca735 100644
--- a/tests/suites/machineidentityfed/azureauth_test.go
+++ b/tests/suites/machineidentity/azureauth_test.go
@@ -1,4 +1,4 @@
-package machineidentityfed_test
+package machineidentity_test
import (
"crypto/rsa"
diff --git a/tests/suites/machineidentityfed/fedhelpers_test.go b/tests/suites/machineidentity/fedhelpers_test.go
similarity index 99%
rename from tests/suites/machineidentityfed/fedhelpers_test.go
rename to tests/suites/machineidentity/fedhelpers_test.go
index 24d70a0390..cf9d5a2931 100644
--- a/tests/suites/machineidentityfed/fedhelpers_test.go
+++ b/tests/suites/machineidentity/fedhelpers_test.go
@@ -1,4 +1,4 @@
-package machineidentityfed_test
+package machineidentity_test
import (
"bytes"
diff --git a/tests/suites/machineidentityfed/gcpauth_test.go b/tests/suites/machineidentity/gcpauth_test.go
similarity index 99%
rename from tests/suites/machineidentityfed/gcpauth_test.go
rename to tests/suites/machineidentity/gcpauth_test.go
index 6c4d0b5985..f1a15aa199 100644
--- a/tests/suites/machineidentityfed/gcpauth_test.go
+++ b/tests/suites/machineidentity/gcpauth_test.go
@@ -1,4 +1,4 @@
-package machineidentityfed_test
+package machineidentity_test
import (
"crypto/rsa"
diff --git a/tests/suites/machineidentityfed/jwtauthjwks_test.go b/tests/suites/machineidentity/jwtauthjwks_test.go
similarity index 99%
rename from tests/suites/machineidentityfed/jwtauthjwks_test.go
rename to tests/suites/machineidentity/jwtauthjwks_test.go
index 4664632c23..2e0f2f325b 100644
--- a/tests/suites/machineidentityfed/jwtauthjwks_test.go
+++ b/tests/suites/machineidentity/jwtauthjwks_test.go
@@ -1,4 +1,4 @@
-package machineidentityfed_test
+package machineidentity_test
import (
"net/http"
diff --git a/tests/suites/machineidentityfed/kubernetesauth_test.go b/tests/suites/machineidentity/kubernetesauth_test.go
similarity index 99%
rename from tests/suites/machineidentityfed/kubernetesauth_test.go
rename to tests/suites/machineidentity/kubernetesauth_test.go
index 5dad2c8688..46de4a8759 100644
--- a/tests/suites/machineidentityfed/kubernetesauth_test.go
+++ b/tests/suites/machineidentity/kubernetesauth_test.go
@@ -1,4 +1,4 @@
-package machineidentityfed_test
+package machineidentity_test
import (
"net/http"
diff --git a/tests/suites/machineidentityfed/ldapauth_test.go b/tests/suites/machineidentity/ldapauth_test.go
similarity index 99%
rename from tests/suites/machineidentityfed/ldapauth_test.go
rename to tests/suites/machineidentity/ldapauth_test.go
index 5eb9b4249e..ce104a4ee1 100644
--- a/tests/suites/machineidentityfed/ldapauth_test.go
+++ b/tests/suites/machineidentity/ldapauth_test.go
@@ -1,4 +1,4 @@
-package machineidentityfed_test
+package machineidentity_test
import (
"net/http"
diff --git a/tests/suites/machineidentityfed/ociauth_test.go b/tests/suites/machineidentity/ociauth_test.go
similarity index 99%
rename from tests/suites/machineidentityfed/ociauth_test.go
rename to tests/suites/machineidentity/ociauth_test.go
index 597088e894..731777f8b6 100644
--- a/tests/suites/machineidentityfed/ociauth_test.go
+++ b/tests/suites/machineidentity/ociauth_test.go
@@ -1,4 +1,4 @@
-package machineidentityfed_test
+package machineidentity_test
import (
"crypto/rsa"
diff --git a/tests/suites/machineidentityfed/oidcauth_test.go b/tests/suites/machineidentity/oidcauth_test.go
similarity index 99%
rename from tests/suites/machineidentityfed/oidcauth_test.go
rename to tests/suites/machineidentity/oidcauth_test.go
index 609b55a1fd..56f85d0ed6 100644
--- a/tests/suites/machineidentityfed/oidcauth_test.go
+++ b/tests/suites/machineidentity/oidcauth_test.go
@@ -1,4 +1,4 @@
-package machineidentityfed_test
+package machineidentity_test
import (
"crypto/rsa"
diff --git a/tests/suites/machineidentityfed/spiffeauth_test.go b/tests/suites/machineidentity/spiffeauth_test.go
similarity index 99%
rename from tests/suites/machineidentityfed/spiffeauth_test.go
rename to tests/suites/machineidentity/spiffeauth_test.go
index 99b7144d01..f2144559c6 100644
--- a/tests/suites/machineidentityfed/spiffeauth_test.go
+++ b/tests/suites/machineidentity/spiffeauth_test.go
@@ -1,4 +1,4 @@
-package machineidentityfed_test
+package machineidentity_test
import (
"encoding/json"
diff --git a/tests/suites/machineidentityfed/main_test.go b/tests/suites/machineidentityfed/main_test.go
deleted file mode 100644
index 71bae04685..0000000000
--- a/tests/suites/machineidentityfed/main_test.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package machineidentityfed_test
-
-import (
- "testing"
-
- "github.com/Infisical/infisical/tests/harness"
-)
-
-func TestMain(m *testing.M) { harness.Main(m, harness.Shared) }
diff --git a/tests/suites/user/isolated/oauth_test.go b/tests/suites/user/isolated/oauth_test.go
index dcd9617935..a48b70bcc7 100644
--- a/tests/suites/user/isolated/oauth_test.go
+++ b/tests/suites/user/isolated/oauth_test.go
@@ -92,9 +92,12 @@ func TestOAuth_DisabledProvider(t *testing.T) {
// configure writes instance configuration as raw JSON, since the typed body cannot send
// null, and restores it when the test ends.
+//
+// A user writes it rather than h.InstanceAdmin: updateServerCfg reads the caller as a
+// user to check it keeps a login method, and answers 500 for the bootstrap identity.
func configure(t *testing.T, h *harness.Stack, set, restore string) {
t.Helper()
- admin := h.InstanceAdmin(t)
+ admin := serverAdminUser(t, h)
write := func(ctx context.Context, body string) *api.UpdateAdminConfigResponse {
res, err := admin.API.UpdateAdminConfigWithBodyWithResponse(ctx, "application/json", bytes.NewReader([]byte(body)))
require.NoError(t, err)
@@ -109,6 +112,16 @@ func configure(t *testing.T, h *harness.Stack, set, restore string) {
})
}
+// serverAdminUser is a user, outside the tenant under test, promoted to server admin.
+func serverAdminUser(t *testing.T, h *harness.Stack) *harness.Principal {
+ t.Helper()
+ ops := h.NewTenant(t).Admin
+ res, err := h.InstanceAdmin(t).API.GrantAdminAccessToUserWithResponse(t.Context(), ops.ID.String())
+ require.NoError(t, err)
+ require.Equalf(t, http.StatusOK, res.StatusCode(), "granting server admin: %s", apierr.Body(res.Body))
+ return ops
+}
+
func disableGitHub(t *testing.T, h *harness.Stack) {
t.Helper()
configure(t, h,