Skip to content

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

Rename

Daniel Hougaard9387d9aaacef
diff --git a/cli/test/login.go b/cli/test/login.go
deleted file mode 100644
index 0f45914132..0000000000
--- a/cli/test/login.go
+++ /dev/null
@@ -1,29 +0,0 @@
-package tests
-
-import (
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-func MachineIdentityLoginCmd(t *testing.T) {
- SetupCli(t)
-
- if creds.UAAccessToken != "" {
- return
- }
-
- jwtPattern := `^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$`
-
- output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "login", "--method=universal-auth", "--client-id", creds.ClientID, "--client-secret", creds.ClientSecret, "--plain", "--silent")
-
- if err != nil {
- t.Fatalf("error running CLI command: %v", err)
- }
-
- assert.Regexp(t, jwtPattern, output)
-
- creds.UAAccessToken = output
-
- // We can't use snapshot testing here because the output will be different every time
-}
diff --git a/cli/test/login_test.go b/cli/test/login_test.go
index 1d598153a0..0f45914132 100644
--- a/cli/test/login_test.go
+++ b/cli/test/login_test.go
@@ -1,43 +1,29 @@
package tests
import (
- "bytes"
- "fmt"
- "regexp"
"testing"
- "github.com/Infisical/infisical-merge/packages/cmd"
"github.com/stretchr/testify/assert"
)
-func UALoginCmd(t *testing.T) {
- jwtPattern := `^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$`
-
- rootCommand := cmd.NewRootCmd()
-
- commandOutput := new(bytes.Buffer)
- errorOutput := new(bytes.Buffer)
- rootCommand.SetOut(commandOutput)
- rootCommand.SetErr(errorOutput)
+func MachineIdentityLoginCmd(t *testing.T) {
+ SetupCli(t)
- args := []string{
- "login",
+ if creds.UAAccessToken != "" {
+ return
}
- args = append(args, fmt.Sprintf("--method=%s", "universal-auth"))
- args = append(args, fmt.Sprintf("--client-id=%s", creds.ClientID))
- args = append(args, fmt.Sprintf("--client-secret=%s", creds.ClientSecret))
+ jwtPattern := `^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$`
+
+ output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "login", "--method=universal-auth", "--client-id", creds.ClientID, "--client-secret", creds.ClientSecret, "--plain", "--silent")
- rootCommand.SetArgs(args)
- rootCommand.Execute()
+ if err != nil {
+ t.Fatalf("error running CLI command: %v", err)
+ }
- token := commandOutput.String()
+ assert.Regexp(t, jwtPattern, output)
- // We do a match and compare it against true, instead of using assert.Regexp.
- // If the assertion fails, we would be able to see the potential token that was generated in the output console, which would be bad if running in a CI/CD pipeline.
- match, err := regexp.MatchString(jwtPattern, token)
- assert.Nil(t, err)
- assert.True(t, match, "The token does not match the pattern")
+ creds.UAAccessToken = output
- creds.UAAccessToken = token
+ // We can't use snapshot testing here because the output will be different every time
}