Skip to content

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

Feat: Cli integration tests -- login

Daniel Hougaardb79ce8a8807e
diff --git a/cli/test/login_test.go b/cli/test/login_test.go
new file mode 100644
index 0000000000..1d598153a0
--- /dev/null
+++ b/cli/test/login_test.go
@@ -0,0 +1,43 @@
+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)
+
+ args := []string{
+ "login",
+ }
+
+ 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))
+
+ rootCommand.SetArgs(args)
+ rootCommand.Execute()
+
+ token := commandOutput.String()
+
+ // 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 = token
+}