Skip to content

Commit

Permalink
cleanup(pam/integration-tests): Do not hardcode the socket paths (#232)
Browse files Browse the repository at this point in the history
The authd socket paths are hardcoded to a temporary location.

While this is not a problem per se it also may potentially break the
ability of running tests in parallel or in setups where /tmp is not the
the $TMPDIR or $GOTMPDIR.

So, make this just more dynamic by runnig the tape files with an env
variable (we're in a terminal after all!), and run vhs with such
variable set to the temporary socket path that authd provides us
  • Loading branch information
denisonbarbosa authored Feb 27, 2024
2 parents ff21a9c + 1017478 commit ece51bb
Show file tree
Hide file tree
Showing 48 changed files with 260 additions and 260 deletions.
16 changes: 8 additions & 8 deletions pam/integration-tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ func TestCLIAuthenticate(t *testing.T) {
gpasswdOutput := filepath.Join(outDir, "gpasswd", "authenticate.output")
groupsFile := filepath.Join(testutils.TestFamilyPath(t), "gpasswd.group")

socketPath := "/tmp/pam-cli-authenticate-tests.sock"
const socketPathEnv = "AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK"
ctx, cancel := context.WithCancel(context.Background())
_, stopped := testutils.RunDaemon(ctx, t, daemonPath,
testutils.WithSocketPath(socketPath),
socketPath, stopped := testutils.RunDaemon(ctx, t, daemonPath,
testutils.WithEnvironment(grouptests.GPasswdMockEnv(t, gpasswdOutput, groupsFile)...),
)
t.Cleanup(func() {
Expand Down Expand Up @@ -77,6 +76,7 @@ func TestCLIAuthenticate(t *testing.T) {
cmd := exec.Command("vhs", filepath.Join(currentDir, "testdata", "tapes", tc.tape+".tape"))
cmd.Env = testutils.AppendCovEnv(cmd.Env)
cmd.Env = append(cmd.Env, pathEnv)
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", socketPathEnv, socketPath))
cmd.Dir = outDir

out, err := cmd.CombinedOutput()
Expand All @@ -89,7 +89,7 @@ func TestCLIAuthenticate(t *testing.T) {
var got string
splitTmp := strings.Split(string(tmp), "\n")
for i, str := range splitTmp {
if strings.HasPrefix(str, fmt.Sprintf("> ./pam_authd login socket=%s", socketPath)) {
if strings.HasPrefix(str, fmt.Sprintf("> ./pam_authd login socket=${%s}", socketPathEnv)) {
got = strings.Join(splitTmp[i:], "\n")
break
}
Expand Down Expand Up @@ -117,10 +117,9 @@ func TestCLIChangeAuthTok(t *testing.T) {
gpasswdOutput := filepath.Join(outDir, "gpasswd", "chauthtok.output")
groupsFile := filepath.Join(testutils.TestFamilyPath(t), "gpasswd.group")

socketPath := "/tmp/pam-cli-chauthtok-tests.sock"
const socketPathEnv = "AUTHD_TESTS_CLI_AUTHTOK_TESTS_SOCK"
ctx, cancel := context.WithCancel(context.Background())
_, stopped := testutils.RunDaemon(ctx, t, daemonPath,
testutils.WithSocketPath(socketPath),
socketPath, stopped := testutils.RunDaemon(ctx, t, daemonPath,
testutils.WithEnvironment(grouptests.GPasswdMockEnv(t, gpasswdOutput, groupsFile)...),
)
t.Cleanup(func() {
Expand Down Expand Up @@ -158,6 +157,7 @@ func TestCLIChangeAuthTok(t *testing.T) {
cmd := exec.Command("vhs", filepath.Join(currentDir, "testdata", "tapes", tc.tape+".tape"))
cmd.Env = testutils.AppendCovEnv(cmd.Env)
cmd.Env = append(cmd.Env, pathEnv)
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", socketPathEnv, socketPath))
cmd.Dir = outDir

out, err := cmd.CombinedOutput()
Expand All @@ -170,7 +170,7 @@ func TestCLIChangeAuthTok(t *testing.T) {
var got string
splitTmp := strings.Split(string(tmp), "\n")
for i, str := range splitTmp {
if strings.HasPrefix(str, fmt.Sprintf("> ./pam_authd passwd socket=%s", socketPath)) {
if strings.HasPrefix(str, fmt.Sprintf("> ./pam_authd passwd socket=${%s}", socketPathEnv)) {
got = strings.Join(splitTmp[i:], "\n")
break
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Username: user name


Expand Down Expand Up @@ -31,7 +31,7 @@ Username: user name


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Username: user-local-groups


Expand Down Expand Up @@ -64,7 +64,7 @@ Username: user-local-groups


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Select your provider

> 1. local
Expand Down Expand Up @@ -97,7 +97,7 @@ Username: user-local-groups


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Gimme your password
>

Expand Down Expand Up @@ -130,7 +130,7 @@ Gimme your password


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Gimme your password
PAM Authenticate() for user "user-local-groups" exited with success
PAM AcctMgmt() exited with success
Expand Down Expand Up @@ -163,7 +163,7 @@ PAM AcctMgmt() exited with success


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Gimme your password
PAM Authenticate() for user "user-local-groups" exited with success
PAM AcctMgmt() exited with success
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Username: user name


Expand Down Expand Up @@ -31,7 +31,7 @@ Username: user name


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Username: user-can-reset


Expand Down Expand Up @@ -64,7 +64,7 @@ Username: user-can-reset


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Select your provider

> 1. local
Expand Down Expand Up @@ -97,7 +97,7 @@ Username: user-can-reset


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Gimme your password
>

Expand Down Expand Up @@ -130,7 +130,7 @@ Gimme your password


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Enter your new password (3 days until mandatory)
>
>
Expand Down Expand Up @@ -163,7 +163,7 @@ Enter your new password (3 days until mandatory)


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Enter your new password (3 days until mandatory)
>
>
Expand Down Expand Up @@ -196,7 +196,7 @@ Enter your new password (3 days until mandatory)


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Enter your new password (3 days until mandatory)
>
>
Expand Down Expand Up @@ -229,7 +229,7 @@ PAM AcctMgmt() exited with success


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Enter your new password (3 days until mandatory)
>
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Username: user name


Expand Down Expand Up @@ -31,7 +31,7 @@ Username: user name


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Username: user-needs-reset


Expand Down Expand Up @@ -64,7 +64,7 @@ Username: user-needs-reset


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Select your provider

> 1. local
Expand Down Expand Up @@ -97,7 +97,7 @@ Username: user-needs-reset


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Gimme your password
>

Expand Down Expand Up @@ -130,7 +130,7 @@ Gimme your password


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Enter your new password
>
>
Expand Down Expand Up @@ -163,7 +163,7 @@ Enter your new password


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Enter your new password
> *******
>
Expand Down Expand Up @@ -196,7 +196,7 @@ Enter your new password


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Enter your new password
> *******
> *******
Expand Down Expand Up @@ -229,7 +229,7 @@ Enter your new password


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Enter your new password
> *******
PAM Authenticate() for user "user-needs-reset" exited with success
Expand Down Expand Up @@ -262,7 +262,7 @@ PAM AcctMgmt() exited with success


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Enter your new password
> *******
PAM Authenticate() for user "user-needs-reset" exited with success
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Username: user name


Expand Down Expand Up @@ -31,7 +31,7 @@ Username: user name


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Username: user1


Expand Down Expand Up @@ -64,7 +64,7 @@ Username: user1


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Select your provider

> 1. local
Expand Down Expand Up @@ -97,7 +97,7 @@ Username: user1


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Gimme your password
>

Expand Down Expand Up @@ -130,7 +130,7 @@ Gimme your password


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Gimme your password
PAM Authenticate() for user "user1" exited with success
PAM AcctMgmt() exited with success
Expand Down Expand Up @@ -163,7 +163,7 @@ PAM AcctMgmt() exited with success


────────────────────────────────────────────────────────────────────────────────
> ./pam_authd login socket=/tmp/pam-cli-authenticate-tests.sock
> ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}
Gimme your password
PAM Authenticate() for user "user1" exited with success
PAM AcctMgmt() exited with success
Expand Down
Loading

0 comments on commit ece51bb

Please sign in to comment.