Files
threshold/testing/internal/e2e/tests/base/authenticate_primary_test.go
shadowdaoandClaude Sonnet 5.5 962d708fdd Rename Go module paths to repo.anhonesthost.net/CyberCoveLLC/threshold
Rename root, api and sdk module paths (imports, go.mod, go_package,
ldflags, build scripts, buf configs) and regenerate protobuf/gateway
code with the project's pinned toolchain. Wire identifiers unchanged.
api gets a local replace for sdk; root/api/sdk require v0.1.0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 10:33:41 -07:00

60 lines
1.7 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package base_test
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os/exec"
"strings"
"testing"
"github.com/creack/pty"
"repo.anhonesthost.net/CyberCoveLLC/threshold/testing/internal/e2e"
"repo.anhonesthost.net/CyberCoveLLC/threshold/testing/internal/e2e/boundary"
"github.com/stretchr/testify/require"
)
// TestCliAuthenticatePrimary tests the `boundary authenticate` command to ensure that a user can
// more quickly log in using the short-hand form of the command (authenticates using the primary auth
// method).
func TestCliAuthenticatePrimary(t *testing.T) {
e2e.MaybeSkipTest(t)
bc, err := boundary.LoadConfig()
require.NoError(t, err)
var cmd *exec.Cmd
ctx := t.Context()
cmd = exec.CommandContext(ctx, "boundary", "authenticate", "-addr", bc.Address, "-format", "json")
f, err := pty.Start(cmd)
require.NoError(t, err)
t.Cleanup(func() {
err := f.Close()
require.NoError(t, err)
})
_, err = f.Write([]byte(bc.AdminLoginName + "\n"))
require.NoError(t, err)
_, err = f.Write([]byte(bc.AdminLoginPassword + "\n"))
require.NoError(t, err)
_, err = f.Write([]byte{4}) // EOT (End of Transmission - marks end of file stream)
require.NoError(t, err)
// Get last line from output (authentication response)
var buf bytes.Buffer
_, _ = io.Copy(&buf, f)
parts := strings.Split(strings.TrimSpace(buf.String()), "\r\n")
response := parts[len(parts)-1]
var authenticationResult boundary.AuthenticateCliOutput
err = json.Unmarshal([]byte(response), &authenticationResult)
require.NoError(t, err)
require.Equal(t, http.StatusOK, authenticationResult.StatusCode, response)
require.NotEmpty(t, authenticationResult.Item.Attributes["token"])
}