Skip to content

Commit

Permalink
pam/adapter/model: Start user selection only after has been requested
Browse files Browse the repository at this point in the history
So we avoid writing at all in the terminal if user selection is not
required, add tests to verify this behavior
  • Loading branch information
3v1n0 committed Apr 16, 2024
1 parent c1794e5 commit 5077953
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 4 deletions.
1 change: 1 addition & 0 deletions examplebroker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var (
exampleUsers = map[string]userInfoBroker{
"user1": {Password: "goodpass"},
"user2": {Password: "goodpass"},
"user3": {Password: "goodpass"},
"user-mfa": {Password: "goodpass"},
"user-needs-reset": {Password: "goodpass"},
"user-can-reset": {Password: "goodpass"},
Expand Down
6 changes: 4 additions & 2 deletions pam/integration-tests/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestCLIAuthenticate(t *testing.T) {
currentUserNotRoot bool
}{
"Authenticate user successfully": {tape: "simple_auth"},
"Authenticate user successfully with preset user": {tape: "simple_auth_with_preset_user"},
"Authenticate user with mfa": {tape: "mfa_auth"},
"Authenticate user with form mode with button": {tape: "form_with_button"},
"Authenticate user with qr code": {tape: "qr_code"},
Expand All @@ -56,8 +57,9 @@ func TestCLIAuthenticate(t *testing.T) {
"Authenticate user and add it to local group": {tape: "local_group"},
"Authenticate with warnings on unsupported arguments": {tape: "simple_auth_with_unsupported_args"},

"Remember last successful broker and mode": {tape: "remember_broker_and_mode"},
"Autoselect local broker for local user": {tape: "local_user"},
"Remember last successful broker and mode": {tape: "remember_broker_and_mode"},
"Autoselect local broker for local user": {tape: "local_user"},
"Autoselect local broker for local user preset": {tape: "local_user_preset"},

"Deny authentication if current user is not considered as root": {tape: "not_root", currentUserNotRoot: true},

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
> env AUTHD_PAM_CLI_USER=user3 ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOC
K}
Select your provider

> 1. local
2. ExampleBroker


























────────────────────────────────────────────────────────────────────────────────
> env AUTHD_PAM_CLI_USER=user3 ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOC
K}
Gimme your password
>




























────────────────────────────────────────────────────────────────────────────────
> env AUTHD_PAM_CLI_USER=user3 ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOC
K}
Gimme your password
PAM Authenticate() for user "user3" exited with success
PAM AcctMgmt() exited with success
>


























────────────────────────────────────────────────────────────────────────────────
> env AUTHD_PAM_CLI_USER=user3 ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOC
K}
Gimme your password
PAM Authenticate() for user "user3" exited with success
PAM AcctMgmt() exited with success
>


























────────────────────────────────────────────────────────────────────────────────
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
> env AUTHD_PAM_CLI_USER=root ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK
}
PAM Info Message: auth=incomplete
PAM Authenticate() for user "root" exited with error (PAM exit code: 25): The return value shoul
d be ignored by PAM dispatch
PAM AcctMgmt() exited with error (PAM exit code: 26): Critical error - immediate abort
>

























────────────────────────────────────────────────────────────────────────────────
> env AUTHD_PAM_CLI_USER=root ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK
}
PAM Info Message: auth=incomplete
PAM Authenticate() for user "root" exited with error (PAM exit code: 25): The return value shoul
d be ignored by PAM dispatch
PAM AcctMgmt() exited with error (PAM exit code: 26): Critical error - immediate abort
>
>
























────────────────────────────────────────────────────────────────────────────────
> env AUTHD_PAM_CLI_USER=root ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK
}
PAM Info Message: auth=incomplete
PAM Authenticate() for user "root" exited with error (PAM exit code: 25): The return value shoul
d be ignored by PAM dispatch
PAM AcctMgmt() exited with error (PAM exit code: 26): Critical error - immediate abort
>
>
























────────────────────────────────────────────────────────────────────────────────
27 changes: 27 additions & 0 deletions pam/integration-tests/testdata/tapes/local_user_preset.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Output local_user_preset.txt
Output local_user_preset.gif # If we don't specify a .gif output, it will create a default out.gif file.

# Configuration header to standardize the output.
# Does not work with the "Source" command.
Set Width 800
Set Height 500
# TODO: Ideally, we should use Ubuntu Mono. However, the github runner is still on Jammy, which does not have it.
# We should update this to use Ubuntu Mono once the runner is updated.
Set FontFamily "Monospace"
Set FontSize 13
Set Padding 0
Set Margin 0
Set Shell bash

Hide
Type "env AUTHD_PAM_CLI_USER=root ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}"
Enter
Sleep 300ms
Show

Hide
Enter
Sleep 300ms
Show

Sleep 300ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Output simple_auth_with_preset_user.txt
Output simple_auth_with_preset_user.gif # If we don't specify a .gif output, it will create a default out.gif file.

# Configuration header to standardize the output.
# Does not work with the "Source" command.
Set Width 800
Set Height 500
# TODO: Ideally, we should use Ubuntu Mono. However, the github runner is still on Jammy, which does not have it.
# We should update this to use Ubuntu Mono once the runner is updated.
Set FontFamily "Monospace"
Set FontSize 13
Set Padding 0
Set Margin 0
Set Shell bash

Hide
Type "env AUTHD_PAM_CLI_USER=user3 ./pam_authd login socket=${AUTHD_TESTS_CLI_AUTHENTICATE_TESTS_SOCK}"
Enter
Sleep 300ms
Show

Hide
Type "2"
Sleep 300ms
Show

Hide
Type "goodpass"
Enter
Sleep 2s
Show

Sleep 300ms
1 change: 0 additions & 1 deletion pam/internal/adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func (m *UIModel) Init() tea.Cmd {
m.authenticationModel = newAuthenticationModel(m.Client, m.ClientType)
cmds = append(cmds, m.authenticationModel.Init())

cmds = append(cmds, m.changeStage(pam_proto.Stage_userSelection))
return tea.Batch(cmds...)
}

Expand Down
3 changes: 2 additions & 1 deletion pam/main-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func main() {
execModule := os.Getenv("AUTHD_PAM_EXEC_MODULE")
cliPath := os.Getenv("AUTHD_PAM_CLI_PATH")
testName := os.Getenv("AUTHD_PAM_CLI_TEST_NAME")
pamUser := os.Getenv("AUTHD_PAM_CLI_USER")

tmpDir, err := os.MkdirTemp(os.TempDir(), "pam-cli-tester-")
if err != nil {
Expand Down Expand Up @@ -73,7 +74,7 @@ func main() {
log.Fatalf("Can't create service file %s: %v", serviceFile, err)
}

tx, err := pam.StartConfDir(filepath.Base(serviceFile), "", pam.ConversationFunc(
tx, err := pam.StartConfDir(filepath.Base(serviceFile), pamUser, pam.ConversationFunc(
func(style pam.Style, msg string) (string, error) {
switch style {
case pam.TextInfo:
Expand Down

0 comments on commit 5077953

Please sign in to comment.