fix(e2e): Fix authentication flakiness
There was a misunderstanding of how goroutines work. Turns out, the goroutine uses the same keyring as the main routine, which can result in some conflicts depending on when the goroutine executes
This commit is contained in:
1 parent
c1449c4fd8
commit
f4a38a7fc9
2 files changed
+35
-1
No files matched your search
@@ -3,6 +3,7 @@ package boundary
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@@ -20,6 +21,11 @@ type config struct {
|
||||
AdminLoginPassword string `envconfig:"E2E_PASSWORD_ADMIN_PASSWORD" required:"true"`
|
||||
}
|
||||
|
||||
type authenticateCliOutput struct {
|
||||
Item *authmethods.AuthenticateResult
|
||||
response *api.Response
|
||||
}
|
||||
|
||||
func loadConfig() (*config, error) {
|
||||
var c config
|
||||
err := envconfig.Process("", &c)
|
||||
@@ -84,3 +90,29 @@ func AuthenticateCli(t testing.TB, ctx context.Context, loginName string, passwo
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
}
|
||||
|
||||
// GetAuthenticationTokenCli uses the cli to get an auth token that can be used in subsequent
|
||||
// commands
|
||||
func GetAuthenticationTokenCli(t testing.TB, ctx context.Context, loginName string, password string) string {
|
||||
c, err := loadConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"authenticate", "password",
|
||||
"-addr", c.Address,
|
||||
"-auth-method-id", c.AuthMethodId,
|
||||
"-login-name", loginName,
|
||||
"-password", "env://E2E_TEST_BOUNDARY_PASSWORD",
|
||||
"-format", "json",
|
||||
),
|
||||
e2e.WithEnv("E2E_TEST_BOUNDARY_PASSWORD", password),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
var authenticationResult authenticateCliOutput
|
||||
err = json.Unmarshal(output.Stdout, &authenticationResult)
|
||||
require.NoError(t, err)
|
||||
|
||||
return fmt.Sprint(authenticationResult.Item.Attributes["token"])
|
||||
}
|
||||
@@ -106,11 +106,12 @@ func TestCliSessionCancelUser(t *testing.T) {
|
||||
ctxCancel, cancel := context.WithCancel(context.Background())
|
||||
errChan := make(chan *e2e.CommandResult)
|
||||
go func() {
|
||||
boundary.AuthenticateCli(t, ctx, acctName, acctPassword)
|
||||
token := boundary.GetAuthenticationTokenCli(t, ctx, acctName, acctPassword)
|
||||
t.Log("Starting session as user...")
|
||||
errChan <- e2e.RunCommand(ctxCancel, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect",
|
||||
"-token", "env://E2E_AUTH_TOKEN",
|
||||
"-target-id", newTargetId,
|
||||
"-exec", "/usr/bin/ssh", "--",
|
||||
"-l", c.TargetSshUser,
|
||||
@@ -122,6 +123,7 @@ func TestCliSessionCancelUser(t *testing.T) {
|
||||
"{{boundary.ip}}",
|
||||
"hostname -i; sleep 60",
|
||||
),
|
||||
e2e.WithEnv("E2E_AUTH_TOKEN", token),
|
||||
)
|
||||
}()
|
||||
t.Cleanup(cancel)
|
||||
|
||||
Reference in new issue
Block a user