Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
tests: LDAP SSO suite and org integration gating tests
Claude966d4ee69b15
diff --git a/tests/suites/orgintegration/externalkms_test.go b/tests/suites/orgintegration/externalkms_test.gonew file mode 100644index 0000000000..b2a6c4e7ad--- /dev/null+++ b/tests/suites/orgintegration/externalkms_test.go@@ -0,0 +1,83 @@+package orgintegration_test++import (+ "net/http"+ "testing"++ "github.com/Infisical/infisical/tests/clients/api"+ "github.com/Infisical/infisical/tests/fakes/license"+ "github.com/Infisical/infisical/tests/harness"+ "github.com/Infisical/infisical/tests/internal/apierr"+ "github.com/Infisical/infisical/tests/internal/id"+ "github.com/stretchr/testify/require"+)++func awsKMSBody() map[string]any {+ return map[string]any{+ "name": "kms-" + id.Short(),+ "configuration": map[string]any{+ "awsRegion": "us-east-1",+ "credential": map[string]any{"type": "access-key", "data": map[string]any{"accessKey": "AKIA" + id.Short(), "secretKey": id.Short()}},+ },+ }+}++func externalKMSCount(t *testing.T, actor *api.ClientWithResponses) int {+ t.Helper()+ res, err := actor.ListExternalKmsWithResponse(t.Context())+ require.NoError(t, err)+ requireStatus(t, http.StatusOK, res.StatusCode(), res.Body)+ return len(res.JSON200.ExternalKmsList)+}++func TestExternalKMS_Create(t *testing.T) {+ t.Parallel()+ h := harness.From(t)++ t.Run("should refuse an external KMS when the plan does not include it and store nothing", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t, harness.WithPlan(license.Enterprise().Without(license.ExternalKMS)))++ // Action+ res, err := tn.Admin.API.CreateAwsExternalKmsWithBodyWithResponse(t.Context(), "application/json", jsonBody(t, awsKMSBody()))++ // Assert+ require.NoError(t, err)+ requireStatus(t, http.StatusBadRequest, res.StatusCode(), res.Body)+ require.Contains(t, apierr.Message(res.Body), "plan restriction")+ require.Zero(t, externalKMSCount(t, tn.Admin.API))+ })++ t.Run("should refuse a member without permission to create a KMS and store nothing", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)+ member := tn.NewMachineIdentity(t, harness.OrgRole("member"))++ // Action+ res, err := member.API.CreateAwsExternalKmsWithBodyWithResponse(t.Context(), "application/json", jsonBody(t, awsKMSBody()))++ // Assert+ require.NoError(t, err)+ requireStatus(t, http.StatusForbidden, res.StatusCode(), res.Body)+ require.Zero(t, externalKMSCount(t, tn.Admin.API))+ })++ t.Run("should still list external KMS configurations when the plan no longer includes it", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t, harness.WithPlan(license.Enterprise().Without(license.ExternalKMS)))++ // Action+ res, err := tn.Admin.API.ListExternalKmsWithResponse(t.Context())++ // Assert+ require.NoError(t, err)+ requireStatus(t, http.StatusOK, res.StatusCode(), res.Body)+ require.Empty(t, res.JSON200.ExternalKmsList)+ })+}diff --git a/tests/suites/orgintegration/githuborgsync_test.go b/tests/suites/orgintegration/githuborgsync_test.gonew file mode 100644index 0000000000..7fedb3c426--- /dev/null+++ b/tests/suites/orgintegration/githuborgsync_test.go@@ -0,0 +1,75 @@+package orgintegration_test++import (+ "net/http"+ "testing"++ "github.com/Infisical/infisical/tests/clients/api"+ "github.com/Infisical/infisical/tests/fakes/license"+ "github.com/Infisical/infisical/tests/harness"+ "github.com/Infisical/infisical/tests/internal/apierr"+ "github.com/stretchr/testify/require"+)++func githubOrgSyncBody() api.CreateGithubOrgSyncConfigJSONRequestBody {+ return api.CreateGithubOrgSyncConfigJSONRequestBody{GithubOrgName: "acme", GithubOrgAccessToken: new("ghp_harness")}+}++func requireNoGithubOrgSync(t *testing.T, tn *harness.Tenant) {+ t.Helper()+ res, err := tn.Admin.API.GetGithubOrgSyncConfigWithResponse(t.Context())+ require.NoError(t, err)+ requireStatus(t, http.StatusNotFound, res.StatusCode(), res.Body)+}++func TestGithubOrgSync_Create(t *testing.T) {+ t.Parallel()+ h := harness.From(t)++ t.Run("should answer 404 when the organization has no GitHub org sync config", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)++ // Action+ res, err := tn.Admin.API.GetGithubOrgSyncConfigWithResponse(t.Context())++ // Assert+ require.NoError(t, err)+ requireStatus(t, http.StatusNotFound, res.StatusCode(), res.Body)+ require.Contains(t, apierr.Message(res.Body), "GitHub organization sync config missing")+ })++ t.Run("should refuse a config when the plan does not include GitHub org sync and store nothing", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t, harness.WithPlan(license.Enterprise().Without(license.GithubOrgSync)))++ // Action+ res, err := tn.Admin.API.CreateGithubOrgSyncConfigWithResponse(t.Context(), githubOrgSyncBody())++ // Assert+ require.NoError(t, err)+ requireStatus(t, http.StatusBadRequest, res.StatusCode(), res.Body)+ require.Contains(t, apierr.Message(res.Body), "plan restriction")+ requireNoGithubOrgSync(t, tn)+ })++ t.Run("should refuse a member without permission to configure GitHub org sync and store nothing", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)+ member := tn.NewMachineIdentity(t, harness.OrgRole("member"))++ // Action+ res, err := member.API.CreateGithubOrgSyncConfigWithResponse(t.Context(), githubOrgSyncBody())++ // Assert+ require.NoError(t, err)+ requireStatus(t, http.StatusForbidden, res.StatusCode(), res.Body)+ requireNoGithubOrgSync(t, tn)+ })+}diff --git a/tests/suites/orgintegration/helpers_test.go b/tests/suites/orgintegration/helpers_test.gonew file mode 100644index 0000000000..646b1dd514--- /dev/null+++ b/tests/suites/orgintegration/helpers_test.go@@ -0,0 +1,22 @@+package orgintegration_test++import (+ "bytes"+ "encoding/json"+ "testing"++ "github.com/Infisical/infisical/tests/internal/apierr"+ "github.com/stretchr/testify/require"+)++func jsonBody(t *testing.T, v any) *bytes.Reader {+ t.Helper()+ raw, err := json.Marshal(v)+ require.NoError(t, err)+ return bytes.NewReader(raw)+}++func requireStatus(t *testing.T, want, got int, body []byte) {+ t.Helper()+ require.Equalf(t, want, got, "answered %d: %s", got, apierr.Body(body))+}diff --git a/tests/suites/orgintegration/main_test.go b/tests/suites/orgintegration/main_test.gonew file mode 100644index 0000000000..d750964993--- /dev/null+++ b/tests/suites/orgintegration/main_test.go@@ -0,0 +1,9 @@+package orgintegration_test++import (+ "testing"++ "github.com/Infisical/infisical/tests/harness"+)++func TestMain(m *testing.M) { harness.Main(m, harness.Shared) }diff --git a/tests/suites/orgintegration/workflowintegration_test.go b/tests/suites/orgintegration/workflowintegration_test.gonew file mode 100644index 0000000000..d9335a8c0e--- /dev/null+++ b/tests/suites/orgintegration/workflowintegration_test.go@@ -0,0 +1,45 @@+package orgintegration_test++import (+ "net/http"+ "testing"++ "github.com/Infisical/infisical/tests/clients/api"+ "github.com/Infisical/infisical/tests/harness"+ "github.com/stretchr/testify/require"+)++func TestWorkflowIntegration(t *testing.T) {+ t.Parallel()+ h := harness.From(t)++ t.Run("should list no workflow integrations for a new organization", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)++ // Action+ res, err := tn.Admin.API.ListWorkflowIntegrationsWithResponse(t.Context())++ // Assert+ require.NoError(t, err)+ requireStatus(t, http.StatusOK, res.StatusCode(), res.Body)+ require.Empty(t, *res.JSON200)+ })++ t.Run("should refuse a member without settings create starting a Slack install", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)+ member := tn.NewMachineIdentity(t, harness.OrgRole("member"))++ // Action+ res, err := member.API.GetSlackInstallUrlWithResponse(t.Context(), &api.GetSlackInstallUrlParams{Slug: "alerts"})++ // Assert+ require.NoError(t, err)+ requireStatus(t, http.StatusForbidden, res.StatusCode(), res.Body)+ })+}diff --git a/tests/suites/sso/ldap/config_test.go b/tests/suites/sso/ldap/config_test.gonew file mode 100644index 0000000000..c68907cfb7--- /dev/null+++ b/tests/suites/sso/ldap/config_test.go@@ -0,0 +1,111 @@+package ldap_test++import (+ "net/http"+ "testing"++ "github.com/Infisical/infisical/tests/clients/api"+ "github.com/Infisical/infisical/tests/fakes/ldap"+ "github.com/Infisical/infisical/tests/fakes/license"+ "github.com/Infisical/infisical/tests/harness"+ "github.com/Infisical/infisical/tests/internal/apierr"+ "github.com/stretchr/testify/require"+)++func TestLDAPConfig_Create(t *testing.T) {+ t.Parallel()+ h := harness.From(t)++ t.Run("should store the directory settings when an admin creates a config", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)+ d := newDirectory(t, tn)++ // Action+ res := createConfig(t, tn.Admin.API, d.configBody())++ // Assert+ requireStatus(t, http.StatusOK, res.StatusCode(), res.Body)+ stored := storedConfig(t, tn)+ require.NotNilf(t, stored.JSON200, "reading the config: %s", apierr.Body(stored.Body))+ require.Equal(t, ldap.Service.URL(), stored.JSON200.Url)+ require.Equal(t, d.BindDN, stored.JSON200.BindDN)+ require.Equal(t, "ou=people,"+d.BaseDN, stored.JSON200.SearchBase)+ require.True(t, stored.JSON200.IsActive)+ })++ t.Run("should refuse creation and store nothing when the plan does not include ldap", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t, harness.WithPlan(license.Enterprise().Without(license.LDAP)))+ d := newDirectory(t, tn)++ // Action+ res := createConfig(t, tn.Admin.API, d.configBody())++ // Assert+ requireStatus(t, http.StatusBadRequest, res.StatusCode(), res.Body)+ require.Contains(t, apierr.Message(res.Body), "plan restriction")+ require.Nil(t, storedConfig(t, tn).JSON200)+ })++ t.Run("should refuse creation and store nothing when a member creates a config", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)+ d := newDirectory(t, tn)+ member := tn.NewUser(t, harness.OrgRole("member"))++ // Action+ res := createConfig(t, member.API, d.configBody())++ // Assert+ requireStatus(t, http.StatusForbidden, res.StatusCode(), res.Body)+ require.Nil(t, storedConfig(t, tn).JSON200)+ })+}++func TestLDAPConnection(t *testing.T) {+ t.Parallel()+ h := harness.From(t)++ t.Run("should report a working connection when the bind credentials are right", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)+ d := newDirectory(t, tn)++ // Action+ res, err := tn.Admin.API.TestLdapConnectionWithResponse(t.Context(), api.TestLdapConnectionJSONRequestBody{+ Url: ldap.Service.URL(), BindDN: d.BindDN, BindPass: d.BindPassword,+ })++ // Assert+ require.NoError(t, err)+ requireStatus(t, http.StatusOK, res.StatusCode(), res.Body)+ require.True(t, *res.JSON200)+ })++ t.Run("should report a failed connection when the bind password is wrong", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)+ d := newDirectory(t, tn)++ // Action+ res, err := tn.Admin.API.TestLdapConnectionWithResponse(t.Context(), api.TestLdapConnectionJSONRequestBody{+ Url: ldap.Service.URL(), BindDN: d.BindDN, BindPass: "not-the-password",+ })++ // Assert+ require.NoError(t, err)+ requireStatus(t, http.StatusOK, res.StatusCode(), res.Body)+ require.False(t, *res.JSON200)+ })+}diff --git a/tests/suites/sso/ldap/helpers_test.go b/tests/suites/sso/ldap/helpers_test.gonew file mode 100644index 0000000000..c64edaf9e0--- /dev/null+++ b/tests/suites/sso/ldap/helpers_test.go@@ -0,0 +1,122 @@+package ldap_test++import (+ "bytes"+ "encoding/json"+ "net/http"+ "net/url"+ "testing"++ "github.com/Infisical/infisical/tests/clients/api"+ "github.com/Infisical/infisical/tests/fakes/ldap"+ "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/id"+ "github.com/stretchr/testify/require"+)++// directory is a tenant's LDAP server, seeded with the tenant's own people.+type directory struct {+ *ldap.ControlPlane+ tn *harness.Tenant+}++func newDirectory(t *testing.T, tn *harness.Tenant) *directory {+ t.Helper()+ return &directory{ControlPlane: ldap.Open(t, fixture.FakenetAdmin(t, tn)), tn: tn}+}++// person adds someone who can bind, with a mail attribute, and returns their uid,+// password and email.+func (d *directory) person(t *testing.T, email string) (string, string, string) {+ t.Helper()+ uid := "u" + id.Short()+ password := "pw-" + id.Short()+ d.AddUser(t, uid, password, map[string][]string{+ "mail": {email}, "givenName": {"Ada"}, "sn": {"Lovelace"}, "uidNumber": {id.Short()},+ })+ return uid, password, email+}++func (d *directory) configBody() api.CreateLdapConfigJSONRequestBody {+ return api.CreateLdapConfigJSONRequestBody{+ OrganizationId: d.tn.OrgID.String(),+ IsActive: true,+ Url: ldap.Service.URL(),+ BindDN: d.BindDN,+ BindPass: d.BindPassword,+ SearchBase: "ou=people," + d.BaseDN,+ SearchFilter: new("(uid={{username}})"),+ }+}++func createConfig(t *testing.T, actor *api.ClientWithResponses, body api.CreateLdapConfigJSONRequestBody) *api.CreateLdapConfigResponse {+ t.Helper()+ res, err := actor.CreateLdapConfigWithResponse(t.Context(), body)+ require.NoError(t, err)+ return res+}++// configured gives the tenant a verified mail domain and an active LDAP config against+// its own directory.+func configured(t *testing.T, tn *harness.Tenant) *directory {+ t.Helper()+ fixture.VerifiedEmailDomain(t, tn)+ d := newDirectory(t, tn)+ res := createConfig(t, tn.Admin.API, d.configBody())+ require.Equalf(t, http.StatusOK, res.StatusCode(), "creating the LDAP config: %s", apierr.Body(res.Body))+ return d+}++func storedConfig(t *testing.T, tn *harness.Tenant) *api.GetLdapConfigResponse {+ t.Helper()+ res, err := tn.Admin.API.GetLdapConfigWithResponse(t.Context(), &api.GetLdapConfigParams{OrganizationId: tn.OrgID.String()})+ require.NoError(t, err)+ return res+}++// login posts the directory credentials the way the login form does. The credentials+// are read by the LDAP strategy before the route validates its body, so they are not+// in the generated request type.+func login(t *testing.T, tn *harness.Tenant, username, password string) *api.LoginWithLdapSsoResponse {+ t.Helper()+ raw, err := json.Marshal(map[string]any{"organizationSlug": tn.OrgSlug, "username": username, "password": password})+ require.NoError(t, err)+ res, err := tn.Anonymous(t).LoginWithLdapSsoWithBodyWithResponse(t.Context(), "application/json", bytes.NewReader(raw))+ require.NoError(t, err)+ return res+}++// next is where a successful login sends the browser.+func next(t *testing.T, res *api.LoginWithLdapSsoResponse) *url.URL {+ t.Helper()+ require.Equalf(t, http.StatusOK, res.StatusCode(), "logging in: %s", apierr.Body(res.Body))+ var body struct {+ NextURL string `json:"nextUrl"`+ }+ require.NoError(t, json.Unmarshal(res.Body, &body))+ u, err := url.Parse(body.NextURL)+ require.NoError(t, err)+ return u+}++// completeSignup finishes an SSO signup with the mailed code, as the signup page does.+func completeSignup(t *testing.T, tn *harness.Tenant, signupToken, code string) *api.CompleteAccountSignupV3Response {+ t.Helper()+ var union api.CompleteAccountSignupV3JSONBody+ require.NoError(t, union.FromCompleteAccountSignupV3JSONBody1(api.CompleteAccountSignupV3JSONBody1{+ Type: api.CompleteAccountSignupV3JSONBody1Type("alias"),+ Code: code,+ }))+ raw, err := json.Marshal(union)+ require.NoError(t, err)+ res, err := tn.Client(t, signupToken).CompleteAccountSignupV3WithBodyWithResponse(t.Context(), "application/json", bytes.NewReader(raw))+ require.NoError(t, err)+ return res+}++func requireStatus(t *testing.T, want, got int, body []byte) {+ t.Helper()+ require.Equalf(t, want, got, "answered %d: %s", got, apierr.Body(body))+}diff --git a/tests/suites/sso/ldap/login_test.go b/tests/suites/sso/ldap/login_test.gonew file mode 100644index 0000000000..f3ff6b35dd--- /dev/null+++ b/tests/suites/sso/ldap/login_test.go@@ -0,0 +1,90 @@+package ldap_test++import (+ "net/http"+ "testing"++ "github.com/Infisical/infisical/tests/fixture"+ "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/stretchr/testify/require"+)++func TestLDAPLogin(t *testing.T) {+ t.Parallel()+ h := harness.From(t)++ t.Run("should send a new directory user to SSO signup and mail them a code", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)+ d := configured(t, tn)+ uid, password, email := d.person(t, tn.Email("ldap-"+id.Short()))++ // Action+ res := login(t, tn, uid, password)++ // Assert+ loc := next(t, res)+ require.Equal(t, "/signup/sso", loc.Path)+ require.NotEmpty(t, loc.Query().Get("token"))+ require.Len(t, sso.VerificationCode(t, tn, email), 6)+ })++ t.Run("should accept the user into the org when signup completes with the mailed code", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)+ d := configured(t, tn)+ uid, password, email := d.person(t, tn.Email("ldap-"+id.Short()))+ token := next(t, login(t, tn, uid, password)).Query().Get("token")+ code := sso.VerificationCode(t, tn, email)++ // Action+ res := completeSignup(t, tn, token, code)++ // Assert+ requireStatus(t, http.StatusOK, res.StatusCode(), res.Body)+ membership := fixture.MembershipOf(t, tn, email)+ require.NotNil(t, membership)+ require.Equal(t, "accepted", membership.Status)+ })++ t.Run("should refuse a wrong directory password and create no account", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)+ d := configured(t, tn)+ uid, _, email := d.person(t, tn.Email("ldap-"+id.Short()))++ // Action+ res := login(t, tn, uid, "not-the-password")++ // Assert+ require.Equal(t, http.StatusUnauthorized, res.StatusCode())+ require.Nil(t, fixture.MembershipOf(t, tn, email))+ })++ t.Run("should refuse a directory user whose email is not on a verified domain of the org", func(t *testing.T) {+ t.Parallel()++ // Setup+ tn := h.NewTenant(t)+ d := configured(t, tn)+ email := "outsider-" + id.Short() + "@unverified-" + id.Short() + ".test"+ uid, password, _ := d.person(t, email)++ // Action+ res := login(t, tn, uid, password)++ // Assert+ requireStatus(t, http.StatusBadRequest, res.StatusCode(), res.Body)+ require.Contains(t, apierr.Message(res.Body), "not a part of the accepted domains")+ require.Nil(t, fixture.MembershipOf(t, tn, email))+ })+}diff --git a/tests/suites/sso/ldap/main_test.go b/tests/suites/sso/ldap/main_test.gonew file mode 100644index 0000000000..63bd1b3521--- /dev/null+++ b/tests/suites/sso/ldap/main_test.go@@ -0,0 +1,9 @@+package ldap_test++import (+ "testing"++ "github.com/Infisical/infisical/tests/harness"+)++func TestMain(m *testing.M) { harness.Main(m, harness.Shared) }