mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Rename
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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-_]*$`
|
||||
func MachineIdentityLoginCmd(t *testing.T) {
|
||||
SetupCli(t)
|
||||
|
||||
rootCommand := cmd.NewRootCmd()
|
||||
|
||||
commandOutput := new(bytes.Buffer)
|
||||
errorOutput := new(bytes.Buffer)
|
||||
rootCommand.SetOut(commandOutput)
|
||||
rootCommand.SetErr(errorOutput)
|
||||
|
||||
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-_]*$`
|
||||
|
||||
rootCommand.SetArgs(args)
|
||||
rootCommand.Execute()
|
||||
output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "login", "--method=universal-auth", "--client-id", creds.ClientID, "--client-secret", creds.ClientSecret, "--plain", "--silent")
|
||||
|
||||
token := commandOutput.String()
|
||||
if err != nil {
|
||||
t.Fatalf("error running CLI command: %v", err)
|
||||
}
|
||||
|
||||
// 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")
|
||||
assert.Regexp(t, jwtPattern, output)
|
||||
|
||||
creds.UAAccessToken = token
|
||||
creds.UAAccessToken = output
|
||||
|
||||
// We can't use snapshot testing here because the output will be different every time
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user