Skip to content

Commit 5495017

Browse files
committed
tests: add cases to test parsing and working of disable_local_password in broker.conf
1 parent 8eb4641 commit 5495017

18 files changed

Lines changed: 67 additions & 7 deletions

File tree

authd-oidc-brokers/internal/broker/broker_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ func TestIsAuthenticated(t *testing.T) {
537537
sessionOffline bool
538538
username string
539539
forceProviderAuthentication bool
540+
disableLocalPassword bool
540541
userDoesNotBecomeOwner bool
541542
allUsersAllowed bool
542543
extraGroups []string
@@ -700,6 +701,14 @@ func TestIsAuthenticated(t *testing.T) {
700701
},
701702
address: "127.0.0.1:31315",
702703
},
704+
"Authenticating_with_device_auth_completes_without_newpassword_when_local_password_is_disabled": {
705+
firstSecret: "-",
706+
disableLocalPassword: true,
707+
},
708+
"Authenticating_with_qrcode_completes_without_newpassword_when_local_password_is_disabled": {
709+
firstSecret: "-",
710+
disableLocalPassword: true,
711+
},
703712

704713
"Error_when_authentication_data_is_invalid": {invalidAuthData: true},
705714
"Error_when_secret_can_not_be_decrypted": {firstMode: authmodes.Password, badFirstKey: true},
@@ -776,6 +785,17 @@ func TestIsAuthenticated(t *testing.T) {
776785
token: &tokenOptions{deviceIsDisabled: true},
777786
sessionOffline: true,
778787
},
788+
"Error_when_mode_is_password_and_local_password_is_disabled": {
789+
firstMode: authmodes.Password,
790+
disableLocalPassword: true,
791+
token: &tokenOptions{},
792+
},
793+
"Error_when_session_is_for_changing_password_and_local_password_is_disabled": {
794+
sessionMode: sessionmode.ChangePassword,
795+
firstMode: authmodes.Password,
796+
disableLocalPassword: true,
797+
token: &tokenOptions{},
798+
},
779799
"Error_when_mode_is_invalid": {firstMode: "invalid"},
780800
}
781801
for name, tc := range tests {
@@ -805,6 +825,7 @@ func TestIsAuthenticated(t *testing.T) {
805825
firstUserBecomesOwner: !tc.userDoesNotBecomeOwner,
806826
allUsersAllowed: tc.allUsersAllowed,
807827
forceProviderAuthentication: tc.forceProviderAuthentication,
828+
disableLocalPassword: tc.disableLocalPassword,
808829
extraGroups: tc.extraGroups,
809830
ownerExtraGroups: tc.ownerExtraGroups,
810831
supportsDeviceRegistration: tc.providerSupportsDeviceRegistration,

authd-oidc-brokers/internal/broker/config_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@ issuer = https://issuer.url.com
2828
client_id = client_id
2929
force_provider_authentication = true
3030
extra_scopes = groups,offline_access, some_other_scope
31+
disable_local_password = true
3132
3233
[users]
3334
home_base_dir = /home
3435
allowed_ssh_suffixes = @issuer.url.com
3536
`,
3637

37-
"invalid_boolean_value": `
38+
"invalid_force_provider_authentication_boolean_value": `
3839
[oidc]
3940
issuer = https://issuer.url.com
4041
client_id = client_id
4142
force_provider_authentication = invalid
43+
`,
44+
45+
"invalid_disable_local_password_boolean_value": `
46+
[oidc]
47+
issuer = https://issuer.url.com
48+
client_id = client_id
49+
disable_local_password = invalid
4250
`,
4351

4452
"singles": `
@@ -82,12 +90,13 @@ func TestParseConfig(t *testing.T) {
8290

8391
"Do_not_fail_if_values_contain_a_single_template_delimiter": {configType: "singles"},
8492

85-
"Error_if_file_does_not_exist": {configType: "inexistent", wantErr: true},
86-
"Error_if_file_is_unreadable": {configType: "unreadable", wantErr: true},
87-
"Error_if_file_is_not_updated": {configType: "template", wantErr: true},
88-
"Error_if_drop_in_directory_is_unreadable": {dropInType: "unreadable-dir", wantErr: true},
89-
"Error_if_drop_in_file_is_unreadable": {dropInType: "unreadable-file", wantErr: true},
90-
"Error_if_config_contains_invalid_values": {configType: "invalid_boolean_value", wantErr: true},
93+
"Error_if_file_does_not_exist": {configType: "inexistent", wantErr: true},
94+
"Error_if_file_is_unreadable": {configType: "unreadable", wantErr: true},
95+
"Error_if_file_is_not_updated": {configType: "template", wantErr: true},
96+
"Error_if_drop_in_directory_is_unreadable": {dropInType: "unreadable-dir", wantErr: true},
97+
"Error_if_drop_in_file_is_unreadable": {dropInType: "unreadable-file", wantErr: true},
98+
"Error_if_force_provider_authentication_contains_invalid_boolean_value": {configType: "invalid_force_provider_authentication_boolean_value", wantErr: true},
99+
"Error_if_disable_local_password_contains_invalid_boolean_value": {configType: "invalid_disable_local_password_boolean_value", wantErr: true},
91100
}
92101
for name, tc := range tests {
93102
t.Run(name, func(t *testing.T) {

authd-oidc-brokers/internal/broker/export_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ func (cfg *Config) SetForceProviderAuthentication(value bool) {
2020
cfg.forceProviderAuthentication = value
2121
}
2222

23+
func (cfg *Config) SetDisableLocalPassword(value bool) {
24+
cfg.disableLocalPassword = value
25+
}
26+
2327
func (cfg *Config) SetRegisterDevice(value bool) {
2428
cfg.registerDevice = value
2529
}

authd-oidc-brokers/internal/broker/helper_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type brokerForTestConfig struct {
2626
broker.Config
2727
issuerURL string
2828
forceProviderAuthentication bool
29+
disableLocalPassword bool
2930
registerDevice bool
3031
allowedUsers map[string]struct{}
3132
allUsersAllowed bool
@@ -60,6 +61,9 @@ func newBrokerForTests(t *testing.T, cfg *brokerForTestConfig) (b *broker.Broker
6061
if cfg.forceProviderAuthentication {
6162
cfg.SetForceProviderAuthentication(cfg.forceProviderAuthentication)
6263
}
64+
if cfg.disableLocalPassword {
65+
cfg.SetDisableLocalPassword(cfg.disableLocalPassword)
66+
}
6367
if cfg.registerDevice {
6468
cfg.SetRegisterDevice(cfg.registerDevice)
6569
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Definitely a token
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
access: granted
2+
data: '{"userinfo":{"name":"test-user@email.com","uuid":"test-user-id","dir":"/home/test-user@email.com","shell":"/usr/bin/bash","gecos":"test-user@email.com","groups":[{"name":"remote-test-group","ugid":"12345"},{"name":"local-test-group","ugid":""}]}}'
3+
err: <nil>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Definitely a token
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
access: granted
2+
data: '{"userinfo":{"name":"test-user@email.com","uuid":"test-user-id","dir":"/home/test-user@email.com","shell":"/usr/bin/bash","gecos":"test-user@email.com","groups":[{"name":"remote-test-group","ugid":"12345"},{"name":"local-test-group","ugid":""}]}}'
3+
err: <nil>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Definitely a hashed password
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Definitely a token

0 commit comments

Comments
 (0)