mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 05:27:48 +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
|
|
||||||
}
|
|
||||||
+13
-27
@@ -1,43 +1,29 @@
|
|||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"regexp"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Infisical/infisical-merge/packages/cmd"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UALoginCmd(t *testing.T) {
|
func MachineIdentityLoginCmd(t *testing.T) {
|
||||||
jwtPattern := `^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$`
|
SetupCli(t)
|
||||||
|
|
||||||
rootCommand := cmd.NewRootCmd()
|
if creds.UAAccessToken != "" {
|
||||||
|
return
|
||||||
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"))
|
jwtPattern := `^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$`
|
||||||
args = append(args, fmt.Sprintf("--client-id=%s", creds.ClientID))
|
|
||||||
args = append(args, fmt.Sprintf("--client-secret=%s", creds.ClientSecret))
|
|
||||||
|
|
||||||
rootCommand.SetArgs(args)
|
output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "login", "--method=universal-auth", "--client-id", creds.ClientID, "--client-secret", creds.ClientSecret, "--plain", "--silent")
|
||||||
rootCommand.Execute()
|
|
||||||
|
|
||||||
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.
|
assert.Regexp(t, jwtPattern, output)
|
||||||
// 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
|
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