diff --git a/cmd/authd/daemon/daemon_test.go b/cmd/authd/daemon/daemon_test.go index 767787d15..b889147fe 100644 --- a/cmd/authd/daemon/daemon_test.go +++ b/cmd/authd/daemon/daemon_test.go @@ -128,13 +128,13 @@ func TestAppRunFailsOnComponentsCreationAndQuit(t *testing.T) { cachePathBehavior int socketPathBehavior int }{ - "Error on existing cache path not being a directory": {cachePathBehavior: dirIsFile}, - "Error on existing cache path with invalid permissions": {cachePathBehavior: hasWrongPermission}, - "Error on missing parent cache directory": {cachePathBehavior: parentDirDoesNotExists}, + "Error_on_existing_cache_path_not_being_a_directory": {cachePathBehavior: dirIsFile}, + "Error_on_existing_cache_path_with_invalid_permissions": {cachePathBehavior: hasWrongPermission}, + "Error_on_missing_parent_cache_directory": {cachePathBehavior: parentDirDoesNotExists}, - "Error on grpc daemon creation failure": {socketPathBehavior: dirIsFile}, + "Error_on_grpc_daemon_creation_failure": {socketPathBehavior: dirIsFile}, - "Error on manager creationg failure": {cacheDBBehavior: hasWrongPermission}, + "Error_on_manager_creationg_failure": {cacheDBBehavior: hasWrongPermission}, } for name, tc := range testCases { diff --git a/cmd/authd/daemon/migration_test.go b/cmd/authd/daemon/migration_test.go index 23cb2aaa7..03661ae92 100644 --- a/cmd/authd/daemon/migration_test.go +++ b/cmd/authd/daemon/migration_test.go @@ -23,26 +23,26 @@ func TestMigrateOldCacheDir(t *testing.T) { wantOldDirExists bool wantNewDirExists bool }{ - "Success if old dir does not exist": {oldDirExists: false, newDirExists: false}, - "Success if old dir exists and new dir does not": { + "Success_if_old_dir_does_not_exist": {oldDirExists: false, newDirExists: false}, + "Success_if_old_dir_exists_and_new_dir_does_not": { oldDirExists: true, newDirExists: false, wantOldDirExists: false, wantNewDirExists: true, wantDbInNewDir: true, }, - "Success if old dir exists and new dir exists": { + "Success_if_old_dir_exists_and_new_dir_exists": { oldDirExists: true, newDirExists: true, wantOldDirExists: true, wantNewDirExists: true, }, - "Success if old dir exists but is unreadable": { + "Success_if_old_dir_exists_but_is_unreadable": { oldDirExists: true, oldDirUnreadable: true, }, - "Error if new dir exists but is unreadable": { + "Error_if_new_dir_exists_but_is_unreadable": { oldDirExists: true, newDirExists: true, newDirUnreadable: true, diff --git a/cmd/authd/main_test.go b/cmd/authd/main_test.go index 8e79d9362..5c7ed40bf 100644 --- a/cmd/authd/main_test.go +++ b/cmd/authd/main_test.go @@ -49,16 +49,16 @@ func TestRun(t *testing.T) { wantReturnCode int }{ - "Run and exit successfully": {}, - "Run and return error": {runError: true, wantReturnCode: 1}, - "Run and return usage error": {usageErrorReturn: true, runError: true, wantReturnCode: 2}, - "Run and usage error only does not fail": {usageErrorReturn: true, runError: false, wantReturnCode: 0}, + "Run_and_exit_successfully": {}, + "Run_and_return_error": {runError: true, wantReturnCode: 1}, + "Run_and_return_usage_error": {usageErrorReturn: true, runError: true, wantReturnCode: 2}, + "Run_and_usage_error_only_does_not_fail": {usageErrorReturn: true, runError: false, wantReturnCode: 0}, // Signals handling - "Send SIGINT exits": {sendSig: syscall.SIGINT}, - "Send SIGTERM exits": {sendSig: syscall.SIGTERM}, - "Send SIGHUP without exiting": {sendSig: syscall.SIGHUP}, - "Send SIGHUP with exit": {sendSig: syscall.SIGHUP, hupReturn: true}, + "Send_SIGINT_exits": {sendSig: syscall.SIGINT}, + "Send_SIGTERM_exits": {sendSig: syscall.SIGTERM}, + "Send_SIGHUP_without_exiting": {sendSig: syscall.SIGHUP}, + "Send_SIGHUP_with_exit": {sendSig: syscall.SIGHUP, hupReturn: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/brokers/broker_test.go b/internal/brokers/broker_test.go index 4b979a0b1..c607a1f2f 100644 --- a/internal/brokers/broker_test.go +++ b/internal/brokers/broker_test.go @@ -47,18 +47,18 @@ func TestNewBroker(t *testing.T) { wantErr bool }{ - "No config means local broker": {configFile: "-"}, - "Successfully create broker with correct config file": {configFile: "valid.conf"}, + "No_config_means_local_broker": {configFile: "-"}, + "Successfully_create_broker_with_correct_config_file": {configFile: "valid.conf"}, // General config errors - "Error when config file is invalid": {configFile: "invalid.conf", wantErr: true}, - "Error when config file does not exist": {configFile: "do not exist.conf", wantErr: true}, + "Error_when_config_file_is_invalid": {configFile: "invalid.conf", wantErr: true}, + "Error_when_config_file_does_not_exist": {configFile: "do not exist.conf", wantErr: true}, // Missing field errors - "Error when config does not have name field": {configFile: "no_name.conf", wantErr: true}, - "Error when config does not have brand_icon field": {configFile: "no_brand_icon.conf", wantErr: true}, - "Error when config does not have dbus_name field": {configFile: "no_dbus_name.conf", wantErr: true}, - "Error when config does not have dbus_object field": {configFile: "no_dbus_object.conf", wantErr: true}, + "Error_when_config_does_not_have_name_field": {configFile: "no_name.conf", wantErr: true}, + "Error_when_config_does_not_have_brand_icon_field": {configFile: "no_brand_icon.conf", wantErr: true}, + "Error_when_config_does_not_have_dbus_name_field": {configFile: "no_dbus_name.conf", wantErr: true}, + "Error_when_config_does_not_have_dbus_object_field": {configFile: "no_dbus_object.conf", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -102,16 +102,16 @@ func TestGetAuthenticationModes(t *testing.T) { wantErr bool }{ - "Get authentication modes and generate validators": {sessionID: "success", supportedUILayouts: []string{"required-entry", "optional-entry"}}, - "Get authentication modes and generate validator ignoring whitespaces in supported values": {sessionID: "success", supportedUILayouts: []string{"layout-with-spaces"}}, - "Get authentication modes and ignores invalid UI layout": {sessionID: "success", supportedUILayouts: []string{"required-entry", "missing-type"}}, - "Get multiple authentication modes and generate validators": {sessionID: "GAM_multiple_modes", supportedUILayouts: []string{"required-entry", "optional-entry"}}, + "Get_authentication_modes_and_generate_validators": {sessionID: "success", supportedUILayouts: []string{"required-entry", "optional-entry"}}, + "Get_authentication_modes_and_generate_validator_ignoring_whitespaces_in_supported_values": {sessionID: "success", supportedUILayouts: []string{"layout-with-spaces"}}, + "Get_authentication_modes_and_ignores_invalid_UI_layout": {sessionID: "success", supportedUILayouts: []string{"required-entry", "missing-type"}}, + "Get_multiple_authentication_modes_and_generate_validators": {sessionID: "GAM_multiple_modes", supportedUILayouts: []string{"required-entry", "optional-entry"}}, - "Does not error out when no authentication modes are returned": {sessionID: "GAM_empty"}, + "Does_not_error_out_when_no_authentication_modes_are_returned": {sessionID: "GAM_empty"}, // broker errors - "Error when getting authentication modes": {sessionID: "GAM_error", wantErr: true}, - "Error when broker returns invalid modes": {sessionID: "GAM_invalid", wantErr: true}, + "Error_when_getting_authentication_modes": {sessionID: "GAM_error", wantErr: true}, + "Error_when_broker_returns_invalid_modes": {sessionID: "GAM_invalid", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -153,23 +153,23 @@ func TestSelectAuthenticationMode(t *testing.T) { wantErr bool }{ - "Successfully select mode with required value": {sessionID: "SAM_success_required_entry"}, - "Successfully select mode with optional value": {sessionID: "SAM_success_optional_entry", supportedUILayouts: []string{"optional-entry"}}, - "Successfully select mode with missing optional value": {sessionID: "SAM_missing_optional_entry", supportedUILayouts: []string{"optional-entry"}}, + "Successfully_select_mode_with_required_value": {sessionID: "SAM_success_required_entry"}, + "Successfully_select_mode_with_optional_value": {sessionID: "SAM_success_optional_entry", supportedUILayouts: []string{"optional-entry"}}, + "Successfully_select_mode_with_missing_optional_value": {sessionID: "SAM_missing_optional_entry", supportedUILayouts: []string{"optional-entry"}}, // broker errors - "Error when selecting invalid auth mode": {sessionID: "SAM_error", wantErr: true}, - "Error when no validators were generated for session": {sessionID: "no-validators", wantErr: true}, + "Error_when_selecting_invalid_auth_mode": {sessionID: "SAM_error", wantErr: true}, + "Error_when_no_validators_were_generated_for_session": {sessionID: "no-validators", wantErr: true}, /* Layout errors */ - "Error when returns no layout": {sessionID: "SAM_no_layout", wantErr: true}, - "Error when returns empty layout": {sessionID: "SAM_empty_layout", wantErr: true}, - "Error when returns layout with no type": {sessionID: "SAM_no_layout_type", wantErr: true}, - "Error when returns layout with invalid type": {sessionID: "SAM_invalid_layout_type", wantErr: true}, - "Error when returns layout without required value": {sessionID: "SAM_missing_required_entry", wantErr: true}, - "Error when returns layout with unknown field": {sessionID: "SAM_unknown_field", wantErr: true}, - "Error when returns layout with invalid required value": {sessionID: "SAM_invalid_required_entry", wantErr: true}, - "Error when returns layout with invalid optional value": {sessionID: "SAM_invalid_optional_entry", wantErr: true}, + "Error_when_returns_no_layout": {sessionID: "SAM_no_layout", wantErr: true}, + "Error_when_returns_empty_layout": {sessionID: "SAM_empty_layout", wantErr: true}, + "Error_when_returns_layout_with_no_type": {sessionID: "SAM_no_layout_type", wantErr: true}, + "Error_when_returns_layout_with_invalid_type": {sessionID: "SAM_invalid_layout_type", wantErr: true}, + "Error_when_returns_layout_without_required_value": {sessionID: "SAM_missing_required_entry", wantErr: true}, + "Error_when_returns_layout_with_unknown_field": {sessionID: "SAM_unknown_field", wantErr: true}, + "Error_when_returns_layout_with_invalid_required_value": {sessionID: "SAM_invalid_required_entry", wantErr: true}, + "Error_when_returns_layout_with_invalid_optional_value": {sessionID: "SAM_invalid_optional_entry", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -212,30 +212,30 @@ func TestIsAuthenticated(t *testing.T) { cancelFirstCall bool }{ - "Successfully authenticate": {sessionID: "success"}, - "Successfully authenticate after cancelling first call": {sessionID: "IA_second_call", secondCall: true}, - "Denies authentication when broker times out": {sessionID: "IA_timeout"}, - "Adds default groups even if broker did not set them": {sessionID: "IA_info_empty_groups"}, - "No error when auth.Next and no data": {sessionID: "IA_next"}, - "No error when broker returns userinfo with empty gecos": {sessionID: "IA_info_empty_gecos"}, - "No error when broker returns userinfo with group with empty UGID": {sessionID: "IA_info_empty_ugid"}, - "No error when broker returns userinfo with mismatching username": {sessionID: "IA_info_mismatching_user_name"}, + "Successfully_authenticate": {sessionID: "success"}, + "Successfully_authenticate_after_cancelling_first_call": {sessionID: "IA_second_call", secondCall: true}, + "Denies_authentication_when_broker_times_out": {sessionID: "IA_timeout"}, + "Adds_default_groups_even_if_broker_did_not_set_them": {sessionID: "IA_info_empty_groups"}, + "No_error_when_auth.Next_and_no_data": {sessionID: "IA_next"}, + "No_error_when_broker_returns_userinfo_with_empty_gecos": {sessionID: "IA_info_empty_gecos"}, + "No_error_when_broker_returns_userinfo_with_group_with_empty_UGID": {sessionID: "IA_info_empty_ugid"}, + "No_error_when_broker_returns_userinfo_with_mismatching_username": {sessionID: "IA_info_mismatching_user_name"}, // broker errors - "Error when authenticating": {sessionID: "IA_error"}, - "Error on empty data even if granted": {sessionID: "IA_empty_data"}, - "Error when broker returns invalid data": {sessionID: "IA_invalid_data"}, - "Error when broker returns invalid access": {sessionID: "IA_invalid_access"}, - "Error when broker returns invalid userinfo": {sessionID: "IA_invalid_userinfo"}, - "Error when broker returns userinfo with empty username": {sessionID: "IA_info_empty_user_name"}, - "Error when broker returns userinfo with empty group name": {sessionID: "IA_info_empty_group_name"}, - "Error when broker returns userinfo with invalid homedir": {sessionID: "IA_info_invalid_home"}, - "Error when broker returns userinfo with invalid shell": {sessionID: "IA_info_invalid_shell"}, - "Error when broker returns data on auth.Next": {sessionID: "IA_next_with_data"}, - "Error when broker returns data on auth.Cancelled": {sessionID: "IA_cancelled_with_data"}, - "Error when broker returns no data on auth.Denied": {sessionID: "IA_denied_without_data"}, - "Error when broker returns no data on auth.Retry": {sessionID: "IA_retry_without_data"}, - "Error when calling IsAuthenticated a second time without cancelling": {sessionID: "IA_second_call", secondCall: true, cancelFirstCall: true}, + "Error_when_authenticating": {sessionID: "IA_error"}, + "Error_on_empty_data_even_if_granted": {sessionID: "IA_empty_data"}, + "Error_when_broker_returns_invalid_data": {sessionID: "IA_invalid_data"}, + "Error_when_broker_returns_invalid_access": {sessionID: "IA_invalid_access"}, + "Error_when_broker_returns_invalid_userinfo": {sessionID: "IA_invalid_userinfo"}, + "Error_when_broker_returns_userinfo_with_empty_username": {sessionID: "IA_info_empty_user_name"}, + "Error_when_broker_returns_userinfo_with_empty_group_name": {sessionID: "IA_info_empty_group_name"}, + "Error_when_broker_returns_userinfo_with_invalid_homedir": {sessionID: "IA_info_invalid_home"}, + "Error_when_broker_returns_userinfo_with_invalid_shell": {sessionID: "IA_info_invalid_shell"}, + "Error_when_broker_returns_data_on_auth.Next": {sessionID: "IA_next_with_data"}, + "Error_when_broker_returns_data_on_auth.Cancelled": {sessionID: "IA_cancelled_with_data"}, + "Error_when_broker_returns_no_data_on_auth.Denied": {sessionID: "IA_denied_without_data"}, + "Error_when_broker_returns_no_data_on_auth.Retry": {sessionID: "IA_retry_without_data"}, + "Error_when_calling_IsAuthenticated_a_second_time_without_cancelling": {sessionID: "IA_second_call", secondCall: true, cancelFirstCall: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -288,8 +288,8 @@ func TestCancelIsAuthenticated(t *testing.T) { wantAnswer string }{ - "Successfully cancels IsAuthenticated": {sessionID: "IA_wait", wantAnswer: auth.Cancelled}, - "Call returns denied if not cancelled": {sessionID: "IA_timeout", wantAnswer: auth.Denied}, + "Successfully_cancels_IsAuthenticated": {sessionID: "IA_wait", wantAnswer: auth.Cancelled}, + "Call_returns_denied_if_not_cancelled": {sessionID: "IA_timeout", wantAnswer: auth.Denied}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -325,9 +325,9 @@ func TestUserPreCheck(t *testing.T) { wantErr bool }{ - "Successfully pre-check user": {username: "user-pre-check"}, + "Successfully_pre-check_user": {username: "user-pre-check"}, - "Error if user is not available": {username: "unexistent", wantErr: true}, + "Error_if_user_is_not_available": {username: "unexistent", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/brokers/internal_test.go b/internal/brokers/internal_test.go index ef644a57e..41abe2727 100644 --- a/internal/brokers/internal_test.go +++ b/internal/brokers/internal_test.go @@ -68,12 +68,12 @@ func TestUnmarshalUserInfo(t *testing.T) { wantErr bool }{ - "Successfully unmarshal complete user info": {jsonInput: completeJSON}, - "Unmarshaling json with empty field keeps its value": {jsonInput: emptyFieldJSON}, - "Unmarshaling json with missing field adds zero value": {jsonInput: missingFieldJSON}, - "Unmarshaling json with additional field ignores it": {jsonInput: additionalFieldJSON}, + "Successfully_unmarshal_complete_user_info": {jsonInput: completeJSON}, + "Unmarshaling_json_with_empty_field_keeps_its_value": {jsonInput: emptyFieldJSON}, + "Unmarshaling_json_with_missing_field_adds_zero_value": {jsonInput: missingFieldJSON}, + "Unmarshaling_json_with_additional_field_ignores_it": {jsonInput: additionalFieldJSON}, - "Error when unmarshaling invalid json": {jsonInput: "invalid-json", wantErr: true}, + "Error_when_unmarshaling_invalid_json": {jsonInput: "invalid-json", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/brokers/layouts/layouts_test.go b/internal/brokers/layouts/layouts_test.go index 123c25870..652bc5034 100644 --- a/internal/brokers/layouts/layouts_test.go +++ b/internal/brokers/layouts/layouts_test.go @@ -17,12 +17,12 @@ func TestOptionalItems(t *testing.T) { want string }{ - "Optional empty item": {want: layouts.Optional + ":"}, - "Optional with one item": { + "Optional_empty_item": {want: layouts.Optional + ":"}, + "Optional_with_one_item": { items: []string{entries.Chars}, want: layouts.Optional + ":" + entries.Chars, }, - "Optional with multiple items": { + "Optional_with_multiple_items": { items: []string{entries.Chars, entries.DigitsPassword}, want: layouts.Optional + ":" + entries.Chars + "," + entries.DigitsPassword, }, @@ -45,12 +45,12 @@ func TestRequiredItems(t *testing.T) { want string }{ - "Required empty item": {want: layouts.Required + ":"}, - "Required with one item": { + "Required_empty_item": {want: layouts.Required + ":"}, + "Required_with_one_item": { items: []string{entries.Chars}, want: layouts.Required + ":" + entries.Chars, }, - "Required with multiple items": { + "Required_with_multiple_items": { items: []string{entries.Chars, entries.DigitsPassword}, want: layouts.Required + ":" + entries.Chars + "," + entries.DigitsPassword, }, @@ -74,34 +74,34 @@ func TestParseItems(t *testing.T) { wantKind string wantItems []string }{ - "Required empty item": {}, - "Required with one item": { + "Required_empty_item": {}, + "Required_with_one_item": { items: layouts.Required + ":" + entries.Chars, wantKind: layouts.Required, wantItems: []string{entries.Chars}, }, - "Required with multiple items": { + "Required_with_multiple_items": { items: layouts.Required + ":" + entries.Chars + ", " + entries.DigitsPassword, wantKind: layouts.Required, wantItems: []string{entries.Chars, entries.DigitsPassword}, }, - "Required with booleans": { + "Required_with_booleans": { items: layouts.RequiredWithBooleans, wantKind: layouts.Required, wantItems: []string{layouts.True, layouts.False}, }, - "Optional empty item": {}, - "Optional with one item": { + "Optional_empty_item": {}, + "Optional_with_one_item": { items: layouts.Optional + ":" + entries.CharsPassword, wantKind: layouts.Optional, wantItems: []string{entries.CharsPassword}, }, - "Optional with multiple items": { + "Optional_with_multiple_items": { items: layouts.Optional + ":" + entries.Digits + " , " + entries.Chars + "," + entries.DigitsPassword, wantKind: layouts.Optional, wantItems: []string{entries.Digits, entries.Chars, entries.DigitsPassword}, }, - "Optional with booleans": { + "Optional_with_booleans": { items: layouts.OptionalWithBooleans, wantKind: layouts.Optional, wantItems: []string{layouts.True, layouts.False}, diff --git a/internal/brokers/manager_test.go b/internal/brokers/manager_test.go index ff36b57e8..6151b3984 100644 --- a/internal/brokers/manager_test.go +++ b/internal/brokers/manager_test.go @@ -28,18 +28,18 @@ func TestNewManager(t *testing.T) { wantErr bool }{ - "Creates all brokers when config dir has only valid brokers": {brokerConfigDir: "valid_brokers"}, - "Creates without autodiscovery when configuredBrokers is set": {brokerConfigDir: "valid_brokers", configuredBrokers: []string{"valid_2.conf"}}, - "Creates only correct brokers when config dir has valid and invalid brokers": {brokerConfigDir: "mixed_brokers"}, - "Creates only local broker when config dir has only invalid ones": {brokerConfigDir: "invalid_brokers"}, - "Creates only local broker when config dir does not exist": {brokerConfigDir: "does/not/exist"}, - "Creates manager even if broker is not exported on dbus": {brokerConfigDir: "not_on_bus"}, - - "Ignores broker configuration file not ending with .conf": {brokerConfigDir: "some_ignored_brokers"}, - "Ignores any unknown sections and fields": {brokerConfigDir: "extra_fields"}, - - "Error when can't connect to system bus": {brokerConfigDir: "valid_brokers", noBus: true, wantErr: true}, - "Error when broker config dir is a file": {brokerConfigDir: "file_config_dir", wantErr: true}, + "Creates_all_brokers_when_config_dir_has_only_valid_brokers": {brokerConfigDir: "valid_brokers"}, + "Creates_without_autodiscovery_when_configuredBrokers_is_set": {brokerConfigDir: "valid_brokers", configuredBrokers: []string{"valid_2.conf"}}, + "Creates_only_correct_brokers_when_config_dir_has_valid_and_invalid_brokers": {brokerConfigDir: "mixed_brokers"}, + "Creates_only_local_broker_when_config_dir_has_only_invalid_ones": {brokerConfigDir: "invalid_brokers"}, + "Creates_only_local_broker_when_config_dir_does_not_exist": {brokerConfigDir: "does/not/exist"}, + "Creates_manager_even_if_broker_is_not_exported_on_dbus": {brokerConfigDir: "not_on_bus"}, + + "Ignores_broker_configuration_file_not_ending_with_.conf": {brokerConfigDir: "some_ignored_brokers"}, + "Ignores_any_unknown_sections_and_fields": {brokerConfigDir: "extra_fields"}, + + "Error_when_can't_connect_to_system_bus": {brokerConfigDir: "valid_brokers", noBus: true, wantErr: true}, + "Error_when_broker_config_dir_is_a_file": {brokerConfigDir: "file_config_dir", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -73,9 +73,9 @@ func TestSetDefaultBrokerForUser(t *testing.T) { wantErr bool }{ - "Successfully assigns existent broker to user": {exists: true}, + "Successfully_assigns_existent_broker_to_user": {exists: true}, - "Error when broker does not exist": {wantErr: true}, + "Error_when_broker_does_not_exist": {wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -129,10 +129,10 @@ func TestBrokerFromSessionID(t *testing.T) { wantBrokerID string wantErr bool }{ - "Successfully returns expected broker": {sessionID: "success"}, - "Returns local broker if sessionID is empty": {wantBrokerID: brokers.LocalBrokerName}, + "Successfully_returns_expected_broker": {sessionID: "success"}, + "Returns_local_broker_if_sessionID_is_empty": {wantBrokerID: brokers.LocalBrokerName}, - "Error if broker does not exist": {sessionID: "does not exist", wantErr: true}, + "Error_if_broker_does_not_exist": {sessionID: "does not exist", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -180,14 +180,14 @@ func TestNewSession(t *testing.T) { wantErr bool }{ - "Successfully start a new auth session": {username: "success"}, - "Successfully start a new passwd session": {username: "success", sessionMode: auth.SessionModePasswd}, - "Successfully start a new session with the correct broker": {username: "success", configuredBrokers: []string{t.Name() + "_Broker1.conf", t.Name() + "_Broker2.conf"}}, - - "Error when broker does not exist": {brokerID: "does_not_exist", wantErr: true}, - "Error when broker does not provide an ID": {username: "NS_no_id", wantErr: true}, - "Error when starting a new session": {username: "NS_error", wantErr: true}, - "Error when broker is not available on dbus": {unavailableBroker: true, wantErr: true}, + "Successfully_start_a_new_auth_session": {username: "success"}, + "Successfully_start_a_new_passwd_session": {username: "success", sessionMode: auth.SessionModePasswd}, + "Successfully_start_a_new_session_with_the_correct_broker": {username: "success", configuredBrokers: []string{t.Name() + "_Broker1.conf", t.Name() + "_Broker2.conf"}}, + + "Error_when_broker_does_not_exist": {brokerID: "does_not_exist", wantErr: true}, + "Error_when_broker_does_not_provide_an_ID": {username: "NS_no_id", wantErr: true}, + "Error_when_starting_a_new_session": {username: "NS_error", wantErr: true}, + "Error_when_broker_is_not_available_on_dbus": {unavailableBroker: true, wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -265,11 +265,11 @@ func TestEndSession(t *testing.T) { wantErr bool }{ - "Successfully end session": {sessionID: "success"}, - "Successfully end session on the correct broker": {sessionID: "success", configuredBrokers: []string{t.Name() + "_Broker1", t.Name() + "_Broker2"}}, + "Successfully_end_session": {sessionID: "success"}, + "Successfully_end_session_on_the_correct_broker": {sessionID: "success", configuredBrokers: []string{t.Name() + "_Broker1", t.Name() + "_Broker2"}}, - "Error when broker does not exist": {brokerID: "does not exist", sessionID: "dont matter", wantErr: true}, - "Error when ending session": {sessionID: "ES_error", wantErr: true}, + "Error_when_broker_does_not_exist": {brokerID: "does not exist", sessionID: "dont matter", wantErr: true}, + "Error_when_ending_session": {sessionID: "ES_error", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/daemon/daemon_test.go b/internal/daemon/daemon_test.go index 93ce7e9a5..984296820 100644 --- a/internal/daemon/daemon_test.go +++ b/internal/daemon/daemon_test.go @@ -43,14 +43,14 @@ func TestNew(t *testing.T) { wantSelectedSocket string wantErr bool }{ - "With socket activation": {wantSelectedSocket: "systemd.sock1"}, - "Socket provided manually is created": {socketType: manualSocket, wantSelectedSocket: "manual.sock"}, - "Socket provided manually wins over socket activation": {socketType: systemdActivationListenerAndManualSocket, wantSelectedSocket: "manual.sock"}, - - "Error when systemd provides multiple sockets": {socketType: systemdActivationListenerMultipleSockets, wantErr: true}, - "Error when systemd activation fails": {socketType: systemdActivationListenerFails, wantErr: true}, - "Error when systemd activated socket does not exists": {socketType: systemdActivationListenerSocketDoesNotExists, wantErr: true}, - "Error when manually provided socket path does not exists": {socketType: manualSocketParentDirectoryDoesNotExists, wantErr: true}, + "With_socket_activation": {wantSelectedSocket: "systemd.sock1"}, + "Socket_provided_manually_is_created": {socketType: manualSocket, wantSelectedSocket: "manual.sock"}, + "Socket_provided_manually_wins_over_socket_activation": {socketType: systemdActivationListenerAndManualSocket, wantSelectedSocket: "manual.sock"}, + + "Error_when_systemd_provides_multiple_sockets": {socketType: systemdActivationListenerMultipleSockets, wantErr: true}, + "Error_when_systemd_activation_fails": {socketType: systemdActivationListenerFails, wantErr: true}, + "Error_when_systemd_activated_socket_does_not_exists": {socketType: systemdActivationListenerSocketDoesNotExists, wantErr: true}, + "Error_when_manually_provided_socket_path_does_not_exists": {socketType: manualSocketParentDirectoryDoesNotExists, wantErr: true}, } for name, tc := range testCases { t.Run(name, func(t *testing.T) { @@ -143,11 +143,11 @@ func TestServe(t *testing.T) { wantErr bool }{ - "Success with systemd notifier": {}, - "Success without systemd notifier": {systemdNotifier: noSystemdNotifier}, + "Success_with_systemd_notifier": {}, + "Success_without_systemd_notifier": {systemdNotifier: noSystemdNotifier}, - "Error on call to Quit before serve": {quitBeforeServe: true, wantErr: true}, - "Error on systemd notifier failing": {systemdNotifier: systemdNotifierFails, wantErr: true}, + "Error_on_call_to_Quit_before_serve": {quitBeforeServe: true, wantErr: true}, + "Error_on_systemd_notifier_failing": {systemdNotifier: systemdNotifierFails, wantErr: true}, } for name, tc := range testCases { t.Run(name, func(t *testing.T) { @@ -211,9 +211,9 @@ func TestQuit(t *testing.T) { wantErr bool }{ - "Graceful stop": {}, - "Graceful stop is blocked on active connection": {activeConnection: true}, - "Force stop drops active connection": {force: true, activeConnection: true}, + "Graceful_stop": {}, + "Graceful_stop_is_blocked_on_active_connection": {activeConnection: true}, + "Force_stop_drops_active_connection": {force: true, activeConnection: true}, } for name, tc := range testCases { t.Run(name, func(t *testing.T) { diff --git a/internal/errno/errno_c_test.go b/internal/errno/errno_c_test.go index 6186712ce..fdd8acb6b 100644 --- a/internal/errno/errno_c_test.go +++ b/internal/errno/errno_c_test.go @@ -43,11 +43,11 @@ func TestErrorValues(t *testing.T) { testCases := map[string]struct { err error }{ - "No error": {}, - "No such file or directory": {err: ErrNoEnt}, - "No such process": {err: ErrSrch}, - "Bad file descriptor": {err: ErrBadf}, - "Operation not permitted": {err: ErrPerm}, + "No_error": {}, + "No_such_file_or_directory": {err: ErrNoEnt}, + "No_such_process": {err: ErrSrch}, + "Bad_file_descriptor": {err: ErrBadf}, + "Operation_not_permitted": {err: ErrPerm}, } for name, tc := range testCases { t.Run(name, func(t *testing.T) { diff --git a/internal/services/errmessages/internal_test.go b/internal/services/errmessages/internal_test.go index 140b9a419..e63f9ee29 100644 --- a/internal/services/errmessages/internal_test.go +++ b/internal/services/errmessages/internal_test.go @@ -20,11 +20,11 @@ func TestRedactErrorInterceptor(t *testing.T) { wantMessage string }{ - "Trim input down to ErrToDisplay": { + "Trim_input_down_to_ErrToDisplay": { inputError: fmt.Errorf("Error to be redacted: %w", ToDisplayError{errors.New("Error to be shown")}), wantMessage: "Error to be shown", }, - "Return original error": { + "Return_original_error": { inputError: errors.New("Not a redacted error"), wantMessage: "Not a redacted error", }, @@ -48,28 +48,28 @@ func TestFormatErrorMessage(t *testing.T) { wantMessage string }{ - "Non-gRPC error is left untouched": { + "Non-gRPC_error_is_left_untouched": { inputError: errors.New("Non-gRPC error"), wantMessage: "Non-gRPC error", }, - "Unrecognized error is left untouched": { + "Unrecognized_error_is_left_untouched": { inputError: status.Error(100, "Unrecognized error"), wantMessage: "error Code(100) from server: Unrecognized error", }, - "Code Canceled is left untouched": { + "Code_Canceled_is_left_untouched": { inputError: status.Error(codes.Canceled, "Canceled error"), wantMessage: "rpc error: code = Canceled desc = Canceled error", }, - "Parse code Unavailable": { + "Parse_code_Unavailable": { inputError: status.Error(codes.Unavailable, "Unavailable error"), wantMessage: "couldn't connect to authd daemon: Unavailable error", }, - "Parse code DeadlineExceeded": { + "Parse_code_DeadlineExceeded": { inputError: status.Error(codes.DeadlineExceeded, "DeadlineExceeded error"), wantMessage: "service took too long to respond. Disconnecting client", }, - "Parse code Unknown": { + "Parse_code_Unknown": { inputError: status.Error(codes.Unknown, "Unknown error"), wantMessage: "Unknown error", }, diff --git a/internal/services/manager_test.go b/internal/services/manager_test.go index a519ee09e..ba58b3ec8 100644 --- a/internal/services/manager_test.go +++ b/internal/services/manager_test.go @@ -29,10 +29,10 @@ func TestNewManager(t *testing.T) { wantErr bool }{ - "Successfully create the manager": {}, + "Successfully_create_the_manager": {}, - "Error when can not create cache": {cacheDir: "doesnotexist", wantErr: true}, - "Error when can not create broker manager": {systemBusSocket: "doesnotexist", wantErr: true}, + "Error_when_can_not_create_cache": {cacheDir: "doesnotexist", wantErr: true}, + "Error_when_can_not_create_broker_manager": {systemBusSocket: "doesnotexist", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/services/nss/nss_test.go b/internal/services/nss/nss_test.go index a1a8615eb..15d6f0b4a 100644 --- a/internal/services/nss/nss_test.go +++ b/internal/services/nss/nss_test.go @@ -53,18 +53,18 @@ func TestGetPasswdByName(t *testing.T) { wantErr bool wantErrNotExists bool }{ - "Return existing user": {username: "user1"}, + "Return_existing_user": {username: "user1"}, - "Precheck user if not in cache": {username: "user-pre-check", shouldPreCheck: true}, - "Prechecked user with upper cases in username has same id as lower case": {username: "User-Pre-Check", shouldPreCheck: true}, + "Precheck_user_if_not_in_cache": {username: "user-pre-check", shouldPreCheck: true}, + "Prechecked_user_with_upper_cases_in_username_has_same_id_as_lower_case": {username: "User-Pre-Check", shouldPreCheck: true}, - "Error in database fetched content": {username: "user1", sourceDB: "invalid.db.yaml", wantErr: true}, - "Error with typed GRPC notfound code on unexisting user": {username: "does-not-exists", wantErr: true, wantErrNotExists: true}, - "Error on missing name": {wantErr: true}, + "Error_in_database_fetched_content": {username: "user1", sourceDB: "invalid.db.yaml", wantErr: true}, + "Error_with_typed_GRPC_notfound_code_on_unexisting_user": {username: "does-not-exists", wantErr: true, wantErrNotExists: true}, + "Error_on_missing_name": {wantErr: true}, - "Error in database fetched content does not trigger precheck": {username: "user1", sourceDB: "invalid.db.yaml", shouldPreCheck: true, wantErr: true}, - "Error if user not in cache and precheck is disabled": {username: "user-pre-check", wantErr: true, wantErrNotExists: true}, - "Error if user not in cache and precheck fails": {username: "does-not-exist", sourceDB: "empty.db.yaml", shouldPreCheck: true, wantErr: true, wantErrNotExists: true}, + "Error_in_database_fetched_content_does_not_trigger_precheck": {username: "user1", sourceDB: "invalid.db.yaml", shouldPreCheck: true, wantErr: true}, + "Error_if_user_not_in_cache_and_precheck_is_disabled": {username: "user-pre-check", wantErr: true, wantErrNotExists: true}, + "Error_if_user_not_in_cache_and_precheck_fails": {username: "does-not-exist", sourceDB: "empty.db.yaml", shouldPreCheck: true, wantErr: true, wantErrNotExists: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -88,11 +88,11 @@ func TestGetPasswdByUID(t *testing.T) { wantErr bool wantErrNotExists bool }{ - "Return existing user": {uid: 1111}, + "Return_existing_user": {uid: 1111}, - "Error in database fetched content": {uid: 1111, sourceDB: "invalid.db.yaml", wantErr: true}, - "Error with typed GRPC notfound code on unexisting user": {uid: 4242, wantErr: true, wantErrNotExists: true}, - "Error on missing uid": {wantErr: true}, + "Error_in_database_fetched_content": {uid: 1111, sourceDB: "invalid.db.yaml", wantErr: true}, + "Error_with_typed_GRPC_notfound_code_on_unexisting_user": {uid: 4242, wantErr: true, wantErrNotExists: true}, + "Error_on_missing_uid": {wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -113,10 +113,10 @@ func TestGetPasswdEntries(t *testing.T) { wantErr bool }{ - "Return all users": {}, - "Return no users": {sourceDB: "empty.db.yaml"}, + "Return_all_users": {}, + "Return_no_users": {sourceDB: "empty.db.yaml"}, - "Error in database fetched content": {sourceDB: "invalid.db.yaml", wantErr: true}, + "Error_in_database_fetched_content": {sourceDB: "invalid.db.yaml", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -140,11 +140,11 @@ func TestGetGroupByName(t *testing.T) { wantErr bool wantErrNotExists bool }{ - "Return existing group": {groupname: "group1"}, + "Return_existing_group": {groupname: "group1"}, - "Error in database fetched content": {groupname: "group1", sourceDB: "invalid.db.yaml", wantErr: true}, - "Error with typed GRPC notfound code on unexisting user": {groupname: "does-not-exists", wantErr: true, wantErrNotExists: true}, - "Error on missing name": {wantErr: true}, + "Error_in_database_fetched_content": {groupname: "group1", sourceDB: "invalid.db.yaml", wantErr: true}, + "Error_with_typed_GRPC_notfound_code_on_unexisting_user": {groupname: "does-not-exists", wantErr: true, wantErrNotExists: true}, + "Error_on_missing_name": {wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -168,11 +168,11 @@ func TestGetGroupByGID(t *testing.T) { wantErr bool wantErrNotExists bool }{ - "Return existing group": {gid: 11111}, + "Return_existing_group": {gid: 11111}, - "Error in database fetched content": {gid: 1111, sourceDB: "invalid.db.yaml", wantErr: true}, - "Error with typed GRPC notfound code on unexisting user": {gid: 4242, wantErr: true, wantErrNotExists: true}, - "Error on missing uid": {wantErr: true}, + "Error_in_database_fetched_content": {gid: 1111, sourceDB: "invalid.db.yaml", wantErr: true}, + "Error_with_typed_GRPC_notfound_code_on_unexisting_user": {gid: 4242, wantErr: true, wantErrNotExists: true}, + "Error_on_missing_uid": {wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -193,10 +193,10 @@ func TestGetGroupEntries(t *testing.T) { wantErr bool }{ - "Return all groups": {}, - "Return no groups": {sourceDB: "empty.db.yaml"}, + "Return_all_groups": {}, + "Return_no_groups": {sourceDB: "empty.db.yaml"}, - "Error in database fetched content": {sourceDB: "invalid.db.yaml", wantErr: true}, + "Error_in_database_fetched_content": {sourceDB: "invalid.db.yaml", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -221,12 +221,12 @@ func TestGetShadowByName(t *testing.T) { wantErr bool wantErrNotExists bool }{ - "Return existing user": {username: "user1"}, + "Return_existing_user": {username: "user1"}, - "Error when not root": {currentUserNotRoot: true, username: "user1", wantErr: true}, - "Error in database fetched content": {username: "user1", sourceDB: "invalid.db.yaml", wantErr: true}, - "Error with typed GRPC notfound code on unexisting user": {username: "does-not-exists", wantErr: true, wantErrNotExists: true}, - "Error on missing name": {wantErr: true}, + "Error_when_not_root": {currentUserNotRoot: true, username: "user1", wantErr: true}, + "Error_in_database_fetched_content": {username: "user1", sourceDB: "invalid.db.yaml", wantErr: true}, + "Error_with_typed_GRPC_notfound_code_on_unexisting_user": {username: "does-not-exists", wantErr: true, wantErrNotExists: true}, + "Error_on_missing_name": {wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -248,11 +248,11 @@ func TestGetShadowEntries(t *testing.T) { wantErr bool }{ - "Return all users": {}, - "Return no users": {sourceDB: "empty.db.yaml"}, + "Return_all_users": {}, + "Return_no_users": {sourceDB: "empty.db.yaml"}, - "Error when not root": {currentUserNotRoot: true, wantErr: true}, - "Error in database fetched content": {sourceDB: "invalid.db.yaml", wantErr: true}, + "Error_when_not_root": {currentUserNotRoot: true, wantErr: true}, + "Error_in_database_fetched_content": {sourceDB: "invalid.db.yaml", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/services/pam/pam_test.go b/internal/services/pam/pam_test.go index 43c85c239..c8b5833ab 100644 --- a/internal/services/pam/pam_test.go +++ b/internal/services/pam/pam_test.go @@ -89,9 +89,9 @@ func TestAvailableBrokers(t *testing.T) { wantErr bool }{ - "Success getting available brokers": {}, + "Success_getting_available_brokers": {}, - "Error when not root": {currentUserNotRoot: true, wantErr: true}, + "Error_when_not_root": {currentUserNotRoot: true, wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -134,15 +134,15 @@ func TestGetPreviousBroker(t *testing.T) { wantBroker string wantErr bool }{ - "Success getting previous broker": {user: "userwithbroker", wantBroker: mockBrokerGeneratedID}, - "For local user, get local broker": {user: currentUsername, wantBroker: brokers.LocalBrokerName}, - "For unmanaged user and only one broker, get local broker": {user: "nonexistent", onlyLocalBroker: true, wantBroker: brokers.LocalBrokerName}, + "Success_getting_previous_broker": {user: "userwithbroker", wantBroker: mockBrokerGeneratedID}, + "For_local_user,_get_local_broker": {user: currentUsername, wantBroker: brokers.LocalBrokerName}, + "For_unmanaged_user_and_only_one_broker,_get_local_broker": {user: "nonexistent", onlyLocalBroker: true, wantBroker: brokers.LocalBrokerName}, - "Returns empty when user does not exist": {user: "nonexistent", wantBroker: ""}, - "Returns empty when user does not have a broker": {user: "userwithoutbroker", wantBroker: ""}, - "Returns empty when broker is not available": {user: "userwithinactivebroker", wantBroker: ""}, + "Returns_empty_when_user_does_not_exist": {user: "nonexistent", wantBroker: ""}, + "Returns_empty_when_user_does_not_have_a_broker": {user: "userwithoutbroker", wantBroker: ""}, + "Returns_empty_when_broker_is_not_available": {user: "userwithinactivebroker", wantBroker: ""}, - "Error when not root": {user: "userwithbroker", currentUserNotRoot: true, wantErr: true}, + "Error_when_not_root": {user: "userwithbroker", currentUserNotRoot: true, wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -197,17 +197,17 @@ func TestSelectBroker(t *testing.T) { wantErr bool }{ - "Successfully select a broker and creates auth session": {username: "success", sessionMode: auth.SessionModeAuth}, - "Successfully select a broker and creates passwd session": {username: "success", sessionMode: auth.SessionModePasswd}, - - "Error when not root": {username: "success", currentUserNotRoot: true, wantErr: true}, - "Error when username is empty": {wantErr: true}, - "Error when mode is empty": {sessionMode: "-", wantErr: true}, - "Error when mode does not exist": {sessionMode: "does not exist", wantErr: true}, - "Error when brokerID is empty": {username: "empty broker", brokerID: "-", wantErr: true}, - "Error when broker does not exist": {username: "no broker", brokerID: "does not exist", wantErr: true}, - "Error when broker does not provide a session ID": {username: "NS_no_id", wantErr: true}, - "Error when starting the session": {username: "NS_error", wantErr: true}, + "Successfully_select_a_broker_and_creates_auth_session": {username: "success", sessionMode: auth.SessionModeAuth}, + "Successfully_select_a_broker_and_creates_passwd_session": {username: "success", sessionMode: auth.SessionModePasswd}, + + "Error_when_not_root": {username: "success", currentUserNotRoot: true, wantErr: true}, + "Error_when_username_is_empty": {wantErr: true}, + "Error_when_mode_is_empty": {sessionMode: "-", wantErr: true}, + "Error_when_mode_does_not_exist": {sessionMode: "does not exist", wantErr: true}, + "Error_when_brokerID_is_empty": {username: "empty broker", brokerID: "-", wantErr: true}, + "Error_when_broker_does_not_exist": {username: "no broker", brokerID: "does not exist", wantErr: true}, + "Error_when_broker_does_not_provide_a_session_ID": {username: "NS_no_id", wantErr: true}, + "Error_when_starting_the_session": {username: "NS_error", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -269,15 +269,15 @@ func TestGetAuthenticationModes(t *testing.T) { wantErr bool }{ - "Successfully get authentication modes": {}, - "Successfully get multiple authentication modes": {username: "GAM_multiple_modes"}, + "Successfully_get_authentication_modes": {}, + "Successfully_get_multiple_authentication_modes": {username: "GAM_multiple_modes"}, - "Error when not root": {currentUserNotRoot: true, wantErr: true}, - "Error when sessionID is empty": {sessionID: "-", wantErr: true}, - "Error when passing invalid layout": {supportedUILayouts: []*authd.UILayout{emptyType}, wantErr: true}, - "Error when sessionID is invalid": {sessionID: "invalid-session", wantErr: true}, - "Error when getting authentication modes": {username: "GAM_error", wantErr: true}, - "Error when broker returns invalid modes": {username: "GAM_invalid", wantErr: true}, + "Error_when_not_root": {currentUserNotRoot: true, wantErr: true}, + "Error_when_sessionID_is_empty": {sessionID: "-", wantErr: true}, + "Error_when_passing_invalid_layout": {supportedUILayouts: []*authd.UILayout{emptyType}, wantErr: true}, + "Error_when_sessionID_is_invalid": {sessionID: "invalid-session", wantErr: true}, + "Error_when_getting_authentication_modes": {username: "GAM_error", wantErr: true}, + "Error_when_broker_returns_invalid_modes": {username: "GAM_invalid", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -335,24 +335,24 @@ func TestSelectAuthenticationMode(t *testing.T) { wantErr bool }{ - "Successfully select mode with required value": {username: "SAM_success_required_entry", supportedUILayouts: []*authd.UILayout{requiredEntry}}, - "Successfully select mode with missing optional value": {username: "SAM_missing_optional_entry", supportedUILayouts: []*authd.UILayout{optionalEntry}}, + "Successfully_select_mode_with_required_value": {username: "SAM_success_required_entry", supportedUILayouts: []*authd.UILayout{requiredEntry}}, + "Successfully_select_mode_with_missing_optional_value": {username: "SAM_missing_optional_entry", supportedUILayouts: []*authd.UILayout{optionalEntry}}, // service errors - "Error when not root": {username: "SAM_success_required_entry", currentUserNotRoot: true, wantErr: true}, - "Error when sessionID is empty": {sessionID: "-", wantErr: true}, - "Error when session ID is invalid": {sessionID: "invalid-session", wantErr: true}, - "Error when no authmode is selected": {sessionID: "no auth mode", authMode: "-", wantErr: true}, + "Error_when_not_root": {username: "SAM_success_required_entry", currentUserNotRoot: true, wantErr: true}, + "Error_when_sessionID_is_empty": {sessionID: "-", wantErr: true}, + "Error_when_session_ID_is_invalid": {sessionID: "invalid-session", wantErr: true}, + "Error_when_no_authmode_is_selected": {sessionID: "no auth mode", authMode: "-", wantErr: true}, // broker errors - "Error when selecting invalid auth mode": {username: "SAM_error", supportedUILayouts: []*authd.UILayout{requiredEntry}, wantErr: true}, - "Error when broker does not have validators for the session": {username: "does not matter", noValidators: true, wantErr: true}, + "Error_when_selecting_invalid_auth_mode": {username: "SAM_error", supportedUILayouts: []*authd.UILayout{requiredEntry}, wantErr: true}, + "Error_when_broker_does_not_have_validators_for_the_session": {username: "does not matter", noValidators: true, wantErr: true}, /* Layout errors */ - "Error when returns no layout": {username: "SAM_no_layout", supportedUILayouts: []*authd.UILayout{requiredEntry}, wantErr: true}, - "Error when returns layout with no type": {username: "SAM_no_layout_type", supportedUILayouts: []*authd.UILayout{requiredEntry}, wantErr: true}, - "Error when returns layout without required value": {username: "SAM_missing_required_entry", supportedUILayouts: []*authd.UILayout{requiredEntry}, wantErr: true}, - "Error when returns layout with unknown field": {username: "SAM_unknown_field", supportedUILayouts: []*authd.UILayout{requiredEntry}, wantErr: true}, + "Error_when_returns_no_layout": {username: "SAM_no_layout", supportedUILayouts: []*authd.UILayout{requiredEntry}, wantErr: true}, + "Error_when_returns_layout_with_no_type": {username: "SAM_no_layout_type", supportedUILayouts: []*authd.UILayout{requiredEntry}, wantErr: true}, + "Error_when_returns_layout_without_required_value": {username: "SAM_missing_required_entry", supportedUILayouts: []*authd.UILayout{requiredEntry}, wantErr: true}, + "Error_when_returns_layout_with_unknown_field": {username: "SAM_unknown_field", supportedUILayouts: []*authd.UILayout{requiredEntry}, wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -423,27 +423,27 @@ func TestIsAuthenticated(t *testing.T) { // There is no wantErr as it's stored in the golden file. }{ - "Successfully authenticate": {username: "success"}, - "Successfully authenticate if first call is canceled": {username: "IA_second_call", secondCall: true, cancelFirstCall: true}, - "Denies authentication when broker times out": {username: "IA_timeout"}, - "Update existing DB on success": {username: "success", existingDB: "cache-with-user.db"}, - "Update local groups": {username: "success_with_local_groups", localGroupsFile: "valid.group"}, + "Successfully_authenticate": {username: "success"}, + "Successfully_authenticate_if_first_call_is_canceled": {username: "IA_second_call", secondCall: true, cancelFirstCall: true}, + "Denies_authentication_when_broker_times_out": {username: "IA_timeout"}, + "Update_existing_DB_on_success": {username: "success", existingDB: "cache-with-user.db"}, + "Update_local_groups": {username: "success_with_local_groups", localGroupsFile: "valid.group"}, // service errors - "Error when not root": {username: "success", currentUserNotRoot: true}, - "Error when sessionID is empty": {sessionID: "-"}, - "Error when there is no broker": {sessionID: "invalid-session"}, + "Error_when_not_root": {username: "success", currentUserNotRoot: true}, + "Error_when_sessionID_is_empty": {sessionID: "-"}, + "Error_when_there_is_no_broker": {sessionID: "invalid-session"}, // broker errors - "Error when authenticating": {username: "IA_error"}, - "Error on empty data even if granted": {username: "IA_empty_data"}, - "Error when broker returns invalid access": {username: "IA_invalid_access"}, - "Error when broker returns invalid data": {username: "IA_invalid_data"}, - "Error when broker returns invalid userinfo": {username: "IA_invalid_userinfo"}, - "Error when calling second time without cancelling": {username: "IA_second_call", secondCall: true}, + "Error_when_authenticating": {username: "IA_error"}, + "Error_on_empty_data_even_if_granted": {username: "IA_empty_data"}, + "Error_when_broker_returns_invalid_access": {username: "IA_invalid_access"}, + "Error_when_broker_returns_invalid_data": {username: "IA_invalid_data"}, + "Error_when_broker_returns_invalid_userinfo": {username: "IA_invalid_userinfo"}, + "Error_when_calling_second_time_without_cancelling": {username: "IA_second_call", secondCall: true}, // local group error - "Error on updating local groups with unexisting file": {username: "success_with_local_groups", localGroupsFile: "does_not_exists.group"}, + "Error_on_updating_local_groups_with_unexisting_file": {username: "success_with_local_groups", localGroupsFile: "does_not_exists.group"}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -549,7 +549,7 @@ func TestIDGeneration(t *testing.T) { tests := map[string]struct { username string }{ - "Generate ID": {username: "success"}, + "Generate_ID": {username: "success"}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -596,14 +596,14 @@ func TestSetDefaultBrokerForUser(t *testing.T) { wantErr bool }{ - "Set default broker for existing user with no broker": {username: "usersetbroker"}, - "Update default broker for existing user with a broker": {username: "userupdatebroker"}, + "Set_default_broker_for_existing_user_with_no_broker": {username: "usersetbroker"}, + "Update_default_broker_for_existing_user_with_a_broker": {username: "userupdatebroker"}, - "Error when setting default broker to local broker": {username: "userlocalbroker", brokerID: brokers.LocalBrokerName, wantErr: true}, - "Error when not root": {username: "usersetbroker", currentUserNotRoot: true, wantErr: true}, - "Error when username is empty": {wantErr: true}, - "Error when user does not exist ": {username: "doesnotexist", wantErr: true}, - "Error when broker does not exist": {username: "userwithbroker", brokerID: "does not exist", wantErr: true}, + "Error_when_setting_default_broker_to_local_broker": {username: "userlocalbroker", brokerID: brokers.LocalBrokerName, wantErr: true}, + "Error_when_not_root": {username: "usersetbroker", currentUserNotRoot: true, wantErr: true}, + "Error_when_username_is_empty": {wantErr: true}, + "Error_when_user_does_not_exist": {username: "doesnotexist", wantErr: true}, + "Error_when_broker_does_not_exist": {username: "userwithbroker", brokerID: "does not exist", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -656,12 +656,12 @@ func TestEndSession(t *testing.T) { wantErr bool }{ - "Successfully end session": {username: "success"}, + "Successfully_end_session": {username: "success"}, - "Error when not root": {username: "success", currentUserNotRoot: true, wantErr: true}, - "Error when sessionID is empty": {sessionID: "-", wantErr: true}, - "Error when sessionID is invalid": {sessionID: "invalid-session", wantErr: true}, - "Error when ending session": {username: "ES_error", wantErr: true}, + "Error_when_not_root": {username: "success", currentUserNotRoot: true, wantErr: true}, + "Error_when_sessionID_is_empty": {sessionID: "-", wantErr: true}, + "Error_when_sessionID_is_invalid": {sessionID: "invalid-session", wantErr: true}, + "Error_when_ending_session": {username: "ES_error", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/services/permissions/permissions_test.go b/internal/services/permissions/permissions_test.go index 016deb366..64dc93316 100644 --- a/internal/services/permissions/permissions_test.go +++ b/internal/services/permissions/permissions_test.go @@ -31,11 +31,11 @@ func TestIsRequestFromRoot(t *testing.T) { wantErr bool }{ - "Granted if current user considered as root": {}, + "Granted_if_current_user_considered_as_root": {}, - "Error as deny when current user is not root": {currentUserNotRoot: true, wantErr: true}, - "Error as deny when missing peer creds Info": {noPeerCredsInfo: true, wantErr: true}, - "Error as deny when missing auth info creds": {noAuthInfo: true, wantErr: true}, + "Error_as_deny_when_current_user_is_not_root": {currentUserNotRoot: true, wantErr: true}, + "Error_as_deny_when_missing_peer_creds_Info": {noPeerCredsInfo: true, wantErr: true}, + "Error_as_deny_when_missing_auth_info_creds": {noAuthInfo: true, wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/sliceutils/sliceutils_test.go b/internal/sliceutils/sliceutils_test.go index d6e50d205..708d4d64f 100644 --- a/internal/sliceutils/sliceutils_test.go +++ b/internal/sliceutils/sliceutils_test.go @@ -13,22 +13,22 @@ func TestDifference(t *testing.T) { tests := map[string]struct { a, b, want []int }{ - "test difference between two slices": { + "test_difference_between_two_slices": { a: []int{1, 2, 3, 4, 5}, b: []int{3, 4, 5, 6, 7}, want: []int{1, 2}, }, - "test difference between an empty slice and a non-empty slice": { + "test_difference_between_an_empty_slice_and_a_non-empty_slice": { a: []int{}, b: []int{3, 4, 5, 6, 7}, want: []int(nil), }, - "test difference between a non-empty slice and an empty slice": { + "test_difference_between_a_non-empty_slice_and_an_empty_slice": { a: []int{1, 2, 3, 4, 5}, b: []int{}, want: []int{1, 2, 3, 4, 5}, }, - "test difference between two empty slices": { + "test_difference_between_two_empty_slices": { a: []int{}, b: []int{}, want: []int(nil), @@ -51,22 +51,22 @@ func TestIntersection(t *testing.T) { tests := map[string]struct { a, b, want []int }{ - "test intersection between two slices": { + "test_intersection_between_two_slices": { a: []int{1, 2, 3, 4, 5}, b: []int{3, 4, 5, 6, 7}, want: []int{3, 4, 5}, }, - "test intersection between an empty slice and a non-empty slice": { + "test_intersection_between_an_empty_slice_and_a_non-empty_slice": { a: []int{}, b: []int{3, 4, 5, 6, 7}, want: []int(nil), }, - "test intersection between a non-empty slice and an empty slice": { + "test_intersection_between_a_non-empty_slice_and_an_empty_slice": { a: []int{1, 2, 3, 4, 5}, b: []int{}, want: []int(nil), }, - "test intersection between two empty slices": { + "test_intersection_between_two_empty_slices": { a: []int{}, b: []int{}, want: []int(nil), diff --git a/internal/testsdetection/testsdetection_test.go b/internal/testsdetection/testsdetection_test.go index c8d9e41f5..666c89805 100644 --- a/internal/testsdetection/testsdetection_test.go +++ b/internal/testsdetection/testsdetection_test.go @@ -29,9 +29,9 @@ func TestMustBeTestingInProcess(t *testing.T) { wantPanic bool }{ - "Pass when called in an integration tests build": {integrationtestsTag: true, wantPanic: false}, + "Pass_when_called_in_an_integration_tests_build": {integrationtestsTag: true, wantPanic: false}, - "Error (panics) when called in non tests and no integration tests": {integrationtestsTag: false, wantPanic: true}, + "Error_(panics)_when_called_in_non_tests_and_no_integration_tests": {integrationtestsTag: false, wantPanic: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/users/cache/db_test.go b/internal/users/cache/db_test.go index 33e626783..d5641ef35 100644 --- a/internal/users/cache/db_test.go +++ b/internal/users/cache/db_test.go @@ -25,15 +25,15 @@ func TestNew(t *testing.T) { wantErr bool }{ - "New without any initialized database": {}, - "New with already existing database": {dbFile: "multiple_users_and_groups"}, - "New recreates any missing buckets and delete unknowns": {dbFile: "database_with_unknown_bucket"}, - "New removes orphaned user records from UserByID bucket": {dbFile: "orphaned_user_record"}, - - "Error on cacheDir non existent cacheDir": {dbFile: "-", wantErr: true}, - "Error on corrupted db file": {corruptedDbFile: true, wantErr: true}, - "Error on invalid permission on database file": {dbFile: "multiple_users_and_groups", perm: &perm0644, wantErr: true}, - "Error on unreadable database file": {dbFile: "multiple_users_and_groups", perm: &perm0000, wantErr: true}, + "New_without_any_initialized_database": {}, + "New_with_already_existing_database": {dbFile: "multiple_users_and_groups"}, + "New_recreates_any_missing_buckets_and_delete_unknowns": {dbFile: "database_with_unknown_bucket"}, + "New_removes_orphaned_user_records_from_UserByID_bucket": {dbFile: "orphaned_user_record"}, + + "Error_on_cacheDir_non_existent_cacheDir": {dbFile: "-", wantErr: true}, + "Error_on_corrupted_db_file": {corruptedDbFile: true, wantErr: true}, + "Error_on_invalid_permission_on_database_file": {dbFile: "multiple_users_and_groups", perm: &perm0644, wantErr: true}, + "Error_on_unreadable_database_file": {dbFile: "multiple_users_and_groups", perm: &perm0000, wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -163,43 +163,43 @@ func TestUpdateUserEntry(t *testing.T) { wantErr bool }{ // New user - "Insert new user": {}, - "Update last login time for user": {dbFile: "one_user_and_group"}, - "Insert new user without optional gecos field": {userCase: "user1-without-gecos"}, + "Insert_new_user": {}, + "Update_last_login_time_for_user": {dbFile: "one_user_and_group"}, + "Insert_new_user_without_optional_gecos_field": {userCase: "user1-without-gecos"}, // User and Group updates - "Update user by changing attributes": {userCase: "user1-new-attributes", dbFile: "one_user_and_group"}, - "Update user does not change homedir if it exists": {userCase: "user1-new-homedir", dbFile: "one_user_and_group"}, - "Update user by removing optional gecos field if not set": {userCase: "user1-without-gecos", dbFile: "one_user_and_group"}, + "Update_user_by_changing_attributes": {userCase: "user1-new-attributes", dbFile: "one_user_and_group"}, + "Update_user_does_not_change_homedir_if_it_exists": {userCase: "user1-new-homedir", dbFile: "one_user_and_group"}, + "Update_user_by_removing_optional_gecos_field_if_not_set": {userCase: "user1-without-gecos", dbFile: "one_user_and_group"}, // Group updates - "Update user by adding a new group": {groupCases: []string{"group1", "group2"}, dbFile: "one_user_and_group"}, - "Update user by adding a new default group": {groupCases: []string{"group2", "group1"}, dbFile: "one_user_and_group"}, - "Update user by renaming a group": {groupCases: []string{"newgroup1-same-ugid"}, dbFile: "one_user_and_group"}, - "Remove group from user": {groupCases: []string{"group2"}, dbFile: "one_user_and_group"}, - "Update user by adding a new local group": {localGroups: []string{"localgroup1"}, dbFile: "one_user_and_group"}, + "Update_user_by_adding_a_new_group": {groupCases: []string{"group1", "group2"}, dbFile: "one_user_and_group"}, + "Update_user_by_adding_a_new_default_group": {groupCases: []string{"group2", "group1"}, dbFile: "one_user_and_group"}, + "Update_user_by_renaming_a_group": {groupCases: []string{"newgroup1-same-ugid"}, dbFile: "one_user_and_group"}, + "Remove_group_from_user": {groupCases: []string{"group2"}, dbFile: "one_user_and_group"}, + "Update_user_by_adding_a_new_local_group": {localGroups: []string{"localgroup1"}, dbFile: "one_user_and_group"}, // Multi users handling - "Update only user even if we have multiple of them": {dbFile: "multiple_users_and_groups"}, - "Add user to group from another user": {groupCases: []string{"group1", "group2"}, dbFile: "multiple_users_and_groups"}, - "Remove user from a group still part from another user": {userCase: "user3", groupCases: []string{"group3"}, dbFile: "multiple_users_and_groups"}, + "Update_only_user_even_if_we_have_multiple_of_them": {dbFile: "multiple_users_and_groups"}, + "Add_user_to_group_from_another_user": {groupCases: []string{"group1", "group2"}, dbFile: "multiple_users_and_groups"}, + "Remove_user_from_a_group_still_part_from_another_user": {userCase: "user3", groupCases: []string{"group3"}, dbFile: "multiple_users_and_groups"}, // Allowed inconsistent cases - "Invalid value entry in groupByName recreates entries": {dbFile: "invalid_entry_in_groupByName"}, - "Invalid value entry in userByName recreates entries": {dbFile: "invalid_entry_in_userByName"}, - "Invalid value entries in other user and groups do not impact current request": {dbFile: "invalid_entries_but_user_and_group1"}, + "Invalid_value_entry_in_groupByName_recreates_entries": {dbFile: "invalid_entry_in_groupByName"}, + "Invalid_value_entry_in_userByName_recreates_entries": {dbFile: "invalid_entry_in_userByName"}, + "Invalid_value_entries_in_other_user_and_groups_do_not_impact_current_request": {dbFile: "invalid_entries_but_user_and_group1"}, // Renaming errors - "Error when user has conflicting uid": {userCase: "user1-new-name", dbFile: "one_user_and_group", wantErr: true}, + "Error_when_user_has_conflicting_uid": {userCase: "user1-new-name", dbFile: "one_user_and_group", wantErr: true}, // Error cases - "Error on invalid value entry in groupByID": {dbFile: "invalid_entry_in_groupByID", wantErr: true}, - "Error on invalid value entry in userByID": {dbFile: "invalid_entry_in_userByID", wantErr: true}, - "Error on invalid value entry in userToGroups": {dbFile: "invalid_entry_in_userToGroups", wantErr: true}, - "Error on invalid value entry in groupToUsers": {dbFile: "invalid_entry_in_groupToUsers", wantErr: true}, - "Error on invalid value entry in groupToUsers for user dropping from group": {dbFile: "invalid_entry_in_groupToUsers_secondary_group", wantErr: true}, - "Error on invalid value entry in groupByID for user dropping from group": {dbFile: "invalid_entry_in_groupByID_secondary_group", wantErr: true}, - "Error when group has conflicting gid": {groupCases: []string{"newgroup1-diff-ugid"}, dbFile: "one_user_and_group", wantErr: true}, + "Error_on_invalid_value_entry_in_groupByID": {dbFile: "invalid_entry_in_groupByID", wantErr: true}, + "Error_on_invalid_value_entry_in_userByID": {dbFile: "invalid_entry_in_userByID", wantErr: true}, + "Error_on_invalid_value_entry_in_userToGroups": {dbFile: "invalid_entry_in_userToGroups", wantErr: true}, + "Error_on_invalid_value_entry_in_groupToUsers": {dbFile: "invalid_entry_in_groupToUsers", wantErr: true}, + "Error_on_invalid_value_entry_in_groupToUsers_for_user_dropping_from_group": {dbFile: "invalid_entry_in_groupToUsers_secondary_group", wantErr: true}, + "Error_on_invalid_value_entry_in_groupByID_for_user_dropping_from_group": {dbFile: "invalid_entry_in_groupByID_secondary_group", wantErr: true}, + "Error_when_group_has_conflicting_gid": {groupCases: []string{"newgroup1-diff-ugid"}, dbFile: "one_user_and_group", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -245,10 +245,10 @@ func TestUserByID(t *testing.T) { wantErr bool wantErrType error }{ - "Get existing user": {dbFile: "one_user_and_group"}, + "Get_existing_user": {dbFile: "one_user_and_group"}, - "Error on missing user": {wantErrType: cache.NoDataFoundError{}}, - "Error on invalid database entry": {dbFile: "invalid_entry_in_userByID", wantErr: true}, + "Error_on_missing_user": {wantErrType: cache.NoDataFoundError{}}, + "Error_on_invalid_database_entry": {dbFile: "invalid_entry_in_userByID", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -271,10 +271,10 @@ func TestUserByName(t *testing.T) { wantErrType error wantErr bool }{ - "Get existing user": {dbFile: "one_user_and_group"}, + "Get_existing_user": {dbFile: "one_user_and_group"}, - "Error on missing user": {wantErrType: cache.NoDataFoundError{}}, - "Error on invalid database entry": {dbFile: "invalid_entry_in_userByName", wantErr: true}, + "Error_on_missing_user": {wantErrType: cache.NoDataFoundError{}}, + "Error_on_invalid_database_entry": {dbFile: "invalid_entry_in_userByName", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -296,12 +296,12 @@ func TestAllUsers(t *testing.T) { wantErr bool }{ - "Get one user": {dbFile: "one_user_and_group"}, - "Get multiple users": {dbFile: "multiple_users_and_groups"}, + "Get_one_user": {dbFile: "one_user_and_group"}, + "Get_multiple_users": {dbFile: "multiple_users_and_groups"}, - "Get users only rely on valid userByID": {dbFile: "partially_valid_multiple_users_and_groups_only_userByID"}, + "Get_users_only_rely_on_valid_userByID": {dbFile: "partially_valid_multiple_users_and_groups_only_userByID"}, - "Error on some invalid users entry": {dbFile: "invalid_entries_but_user_and_group1", wantErr: true}, + "Error_on_some_invalid_users_entry": {dbFile: "invalid_entries_but_user_and_group1", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -324,11 +324,11 @@ func TestGroupByID(t *testing.T) { wantErr bool wantErrType error }{ - "Get existing group": {dbFile: "one_user_and_group"}, + "Get_existing_group": {dbFile: "one_user_and_group"}, - "Error on missing group": {wantErrType: cache.NoDataFoundError{}}, - "Error on invalid database entry": {dbFile: "invalid_entry_in_groupByID", wantErr: true}, - "Error as missing userByID": {dbFile: "partially_valid_multiple_users_and_groups_groupByID_groupToUsers", wantErr: true}, + "Error_on_missing_group": {wantErrType: cache.NoDataFoundError{}}, + "Error_on_invalid_database_entry": {dbFile: "invalid_entry_in_groupByID", wantErr: true}, + "Error_as_missing_userByID": {dbFile: "partially_valid_multiple_users_and_groups_groupByID_groupToUsers", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -351,11 +351,11 @@ func TestGroupByName(t *testing.T) { wantErr bool wantErrType error }{ - "Get existing group": {dbFile: "one_user_and_group"}, + "Get_existing_group": {dbFile: "one_user_and_group"}, - "Error on missing group": {wantErrType: cache.NoDataFoundError{}}, - "Error on invalid database entry": {dbFile: "invalid_entry_in_groupByName", wantErr: true}, - "Error as missing userByID": {dbFile: "partially_valid_multiple_users_and_groups_groupByID_groupToUsers", wantErr: true}, + "Error_on_missing_group": {wantErrType: cache.NoDataFoundError{}}, + "Error_on_invalid_database_entry": {dbFile: "invalid_entry_in_groupByName", wantErr: true}, + "Error_as_missing_userByID": {dbFile: "partially_valid_multiple_users_and_groups_groupByID_groupToUsers", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -378,11 +378,11 @@ func TestUserGroups(t *testing.T) { wantErr bool wantErrType error }{ - "Get groups of existing user": {dbFile: "one_user_and_group"}, + "Get_groups_of_existing_user": {dbFile: "one_user_and_group"}, - "Error on missing user": {wantErrType: cache.NoDataFoundError{}}, - "Error on invalid database entry": {dbFile: "invalid_entry_in_userToGroups", wantErr: true}, - "Error on missing groupByID": {dbFile: "invalid_entry_in_groupByID", wantErr: true}, + "Error_on_missing_user": {wantErrType: cache.NoDataFoundError{}}, + "Error_on_invalid_database_entry": {dbFile: "invalid_entry_in_userToGroups", wantErr: true}, + "Error_on_missing_groupByID": {dbFile: "invalid_entry_in_groupByID", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -405,14 +405,14 @@ func TestAllGroups(t *testing.T) { wantErr bool wantErrType error }{ - "Get one group": {dbFile: "one_user_and_group"}, - "Get multiple groups": {dbFile: "multiple_users_and_groups"}, + "Get_one_group": {dbFile: "one_user_and_group"}, + "Get_multiple_groups": {dbFile: "multiple_users_and_groups"}, - "Get groups rely on groupByID groupToUsers UserByID": {dbFile: "partially_valid_multiple_users_and_groups_groupByID_groupToUsers_UserByID"}, + "Get_groups_rely_on_groupByID_groupToUsers_UserByID": {dbFile: "partially_valid_multiple_users_and_groups_groupByID_groupToUsers_UserByID"}, - "Error on some invalid groups entry": {dbFile: "invalid_entries_but_user_and_group1", wantErr: true}, - "Error as not only relying on groupByID": {dbFile: "partially_valid_multiple_users_and_groups_only_groupByID", wantErr: true}, - "Error as missing userByID": {dbFile: "partially_valid_multiple_users_and_groups_groupByID_groupToUsers", wantErr: true}, + "Error_on_some_invalid_groups_entry": {dbFile: "invalid_entries_but_user_and_group1", wantErr: true}, + "Error_as_not_only_relying_on_groupByID": {dbFile: "partially_valid_multiple_users_and_groups_only_groupByID", wantErr: true}, + "Error_as_missing_userByID": {dbFile: "partially_valid_multiple_users_and_groups_groupByID_groupToUsers", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -484,11 +484,11 @@ func TestDeleteUser(t *testing.T) { wantErr bool wantErrType error }{ - "Delete existing user": {dbFile: "one_user_and_group"}, - "Delete existing user keeping other users intact": {dbFile: "multiple_users_and_groups"}, + "Delete_existing_user": {dbFile: "one_user_and_group"}, + "Delete_existing_user_keeping_other_users_intact": {dbFile: "multiple_users_and_groups"}, - "Error on missing user": {wantErrType: cache.NoDataFoundError{}}, - "Error on invalid database entry": {dbFile: "invalid_entry_in_userByID", wantErr: true}, + "Error_on_missing_user": {wantErrType: cache.NoDataFoundError{}}, + "Error_on_invalid_database_entry": {dbFile: "invalid_entry_in_userByID", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/users/idgenerator/idgenerator_test.go b/internal/users/idgenerator/idgenerator_test.go index e926d8014..845099c36 100644 --- a/internal/users/idgenerator/idgenerator_test.go +++ b/internal/users/idgenerator/idgenerator_test.go @@ -14,8 +14,8 @@ func TestGenerateID(t *testing.T) { idMin uint32 idMax uint32 }{ - "Generated ID is within the defined range": {input: "test", idMin: 1000, idMax: 2000}, - "Generate ID with minimum ID equal to maximum ID": {input: "test", idMin: 1000, idMax: 1000}, + "Generated_ID_is_within_the_defined_range": {input: "test", idMin: 1000, idMax: 2000}, + "Generate_ID_with_minimum_ID_equal_to_maximum_ID": {input: "test", idMin: 1000, idMax: 1000}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/users/localentries/localgroups_test.go b/internal/users/localentries/localgroups_test.go index 0bab732d2..02212455e 100644 --- a/internal/users/localentries/localgroups_test.go +++ b/internal/users/localentries/localgroups_test.go @@ -24,37 +24,37 @@ func TestUpdatelocalentries(t *testing.T) { wantErr bool }{ // First insertion cases - "Insert new user in existing files with no users in our group": {groupFilePath: "no_users_in_our_groups.group"}, - "Insert new user when no users in any group": {groupFilePath: "no_users.group"}, - "Insert new user in existing files with other users in our group": {groupFilePath: "users_in_our_groups.group"}, - "Insert new user in existing files with multiple other users in our group": {groupFilePath: "multiple_users_in_our_groups.group"}, + "Insert_new_user_in_existing_files_with_no_users_in_our_group": {groupFilePath: "no_users_in_our_groups.group"}, + "Insert_new_user_when_no_users_in_any_group": {groupFilePath: "no_users.group"}, + "Insert_new_user_in_existing_files_with_other_users_in_our_group": {groupFilePath: "users_in_our_groups.group"}, + "Insert_new_user_in_existing_files_with_multiple_other_users_in_our_group": {groupFilePath: "multiple_users_in_our_groups.group"}, // User already in groups - "No-Op for user is already present in both local groups": {groupFilePath: "user_in_both_groups.group"}, - "Insert user in the only local group when not present": {groupFilePath: "user_in_one_group.group"}, - "Insert user in the only local group when not present even with multiple": {groupFilePath: "user_and_others_in_one_groups.group"}, - "Remove user from an additional group without other users": {groupFilePath: "user_in_second_local_group.group"}, - "Remove user from an additional group with other users": {groupFilePath: "user_in_second_local_group_with_others.group"}, - "Add and remove user from multiple groups with one remaining": {groupFilePath: "user_in_many_groups.group"}, + "No-Op_for_user_is_already_present_in_both_local_groups": {groupFilePath: "user_in_both_groups.group"}, + "Insert_user_in_the_only_local_group_when_not_present": {groupFilePath: "user_in_one_group.group"}, + "Insert_user_in_the_only_local_group_when_not_present_even_with_multiple": {groupFilePath: "user_and_others_in_one_groups.group"}, + "Remove_user_from_an_additional_group_without_other_users": {groupFilePath: "user_in_second_local_group.group"}, + "Remove_user_from_an_additional_group_with_other_users": {groupFilePath: "user_in_second_local_group_with_others.group"}, + "Add_and_remove_user_from_multiple_groups_with_one_remaining": {groupFilePath: "user_in_many_groups.group"}, // Flexible accepted cases - "Missing group is ignored": {groupFilePath: "missing_group.group"}, - "Group file with empty line is ignored": {groupFilePath: "empty_line.group"}, + "Missing_group_is_ignored": {groupFilePath: "missing_group.group"}, + "Group_file_with_empty_line_is_ignored": {groupFilePath: "empty_line.group"}, // No new groups - "No-Op for user with no groups and was in none": {newGroups: []string{}, groupFilePath: "no_users_in_our_groups.group"}, - "Remove user with no groups from existing ones": {newGroups: []string{}, groupFilePath: "user_in_both_groups.group"}, + "No-Op_for_user_with_no_groups_and_was_in_none": {newGroups: []string{}, groupFilePath: "no_users_in_our_groups.group"}, + "Remove_user_with_no_groups_from_existing_ones": {newGroups: []string{}, groupFilePath: "user_in_both_groups.group"}, // User removed from groups - "User is added to group they were added to before": {newGroups: []string{"localgroup1"}, oldGroups: []string{"localgroup1"}, groupFilePath: "no_users.group"}, - "User is removed from old groups but not from other groups": {newGroups: []string{}, oldGroups: []string{"localgroup3"}, groupFilePath: "user_in_both_groups.group"}, - "User is not removed from groups they are not part of": {newGroups: []string{}, oldGroups: []string{"localgroup2"}, groupFilePath: "user_in_one_group.group"}, + "User_is_added_to_group_they_were_added_to_before": {newGroups: []string{"localgroup1"}, oldGroups: []string{"localgroup1"}, groupFilePath: "no_users.group"}, + "User_is_removed_from_old_groups_but_not_from_other_groups": {newGroups: []string{}, oldGroups: []string{"localgroup3"}, groupFilePath: "user_in_both_groups.group"}, + "User_is_not_removed_from_groups_they_are_not_part_of": {newGroups: []string{}, oldGroups: []string{"localgroup2"}, groupFilePath: "user_in_one_group.group"}, // Error cases - "Error on missing groups file": {groupFilePath: "does_not_exists.group", wantErr: true}, - "Error when groups file is malformed": {groupFilePath: "malformed_file.group", wantErr: true}, - "Error on any unignored add gpasswd error": {username: "gpasswdfail", groupFilePath: "no_users.group", wantErr: true}, - "Error on any unignored delete gpasswd error": {username: "gpasswdfail", groupFilePath: "gpasswdfail_in_deleted_group.group", wantErr: true}, + "Error_on_missing_groups_file": {groupFilePath: "does_not_exists.group", wantErr: true}, + "Error_when_groups_file_is_malformed": {groupFilePath: "malformed_file.group", wantErr: true}, + "Error_on_any_unignored_add_gpasswd_error": {username: "gpasswdfail", groupFilePath: "no_users.group", wantErr: true}, + "Error_on_any_unignored_delete_gpasswd_error": {username: "gpasswdfail", groupFilePath: "gpasswdfail_in_deleted_group.group", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -101,16 +101,16 @@ func TestCleanlocalentries(t *testing.T) { wantErr bool }{ - "No-op when there are no inactive users": {groupFilePath: "user_in_many_groups.group"}, - "Cleans up user from group": {groupFilePath: "inactive_user_in_one_group.group"}, - "Cleans up user from multiple groups": {groupFilePath: "inactive_user_in_many_groups.group"}, - "Cleans up multiple users from group": {groupFilePath: "inactive_users_in_one_group.group"}, - "Cleans up multiple users from multiple groups": {groupFilePath: "inactive_users_in_many_groups.group"}, - - "Error if there is no active user": {groupFilePath: "user_in_many_groups.group", getUsersReturn: []string{}, wantErr: true}, - "Error on missing groups file": {groupFilePath: "does_not_exists.group", wantErr: true}, - "Error when groups file is malformed": {groupFilePath: "malformed_file.group", wantErr: true}, - "Error on any unignored delete gpasswd error": {groupFilePath: "gpasswdfail_in_deleted_group.group", wantErr: true}, + "No-op_when_there_are_no_inactive_users": {groupFilePath: "user_in_many_groups.group"}, + "Cleans_up_user_from_group": {groupFilePath: "inactive_user_in_one_group.group"}, + "Cleans_up_user_from_multiple_groups": {groupFilePath: "inactive_user_in_many_groups.group"}, + "Cleans_up_multiple_users_from_group": {groupFilePath: "inactive_users_in_one_group.group"}, + "Cleans_up_multiple_users_from_multiple_groups": {groupFilePath: "inactive_users_in_many_groups.group"}, + + "Error_if_there_is_no_active_user": {groupFilePath: "user_in_many_groups.group", getUsersReturn: []string{}, wantErr: true}, + "Error_on_missing_groups_file": {groupFilePath: "does_not_exists.group", wantErr: true}, + "Error_when_groups_file_is_malformed": {groupFilePath: "malformed_file.group", wantErr: true}, + "Error_on_any_unignored_delete_gpasswd_error": {groupFilePath: "gpasswdfail_in_deleted_group.group", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -155,13 +155,13 @@ func TestCleanUserFromlocalentries(t *testing.T) { wantErr bool }{ - "Cleans up user from group": {}, - "Cleans up user from multiple groups": {groupFilePath: "user_in_many_groups.group"}, - "No op if user does not belong to any groups": {username: "groupless"}, + "Cleans_up_user_from_group": {}, + "Cleans_up_user_from_multiple_groups": {groupFilePath: "user_in_many_groups.group"}, + "No_op_if_user_does_not_belong_to_any_groups": {username: "groupless"}, - "Error on missing groups file": {groupFilePath: "does_not_exists.group", wantErr: true}, - "Error when groups file is malformed": {groupFilePath: "malformed_file.group", wantErr: true}, - "Error on any unignored delete gpasswd error": {wantMockFailure: true, wantErr: true}, + "Error_on_missing_groups_file": {groupFilePath: "does_not_exists.group", wantErr: true}, + "Error_when_groups_file_is_malformed": {groupFilePath: "malformed_file.group", wantErr: true}, + "Error_on_any_unignored_delete_gpasswd_error": {wantMockFailure: true, wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/users/manager_test.go b/internal/users/manager_test.go index d7c9d34cd..2c7b8aec5 100644 --- a/internal/users/manager_test.go +++ b/internal/users/manager_test.go @@ -29,17 +29,17 @@ func TestNewManager(t *testing.T) { wantErr bool }{ - "Successfully create manager with default config": {}, - "Successfully create manager with custom config": {uidMin: 10000, uidMax: 20000, gidMin: 10000, gidMax: 20000}, + "Successfully_create_manager_with_default_config": {}, + "Successfully_create_manager_with_custom_config": {uidMin: 10000, uidMax: 20000, gidMin: 10000, gidMax: 20000}, // Corrupted databases - "New recreates any missing buckets and delete unknowns": {dbFile: "database_with_unknown_bucket"}, + "New_recreates_any_missing_buckets_and_delete_unknowns": {dbFile: "database_with_unknown_bucket"}, - "Error when database is corrupted": {corruptedDbFile: true, wantErr: true}, - "Error if cacheDir does not exist": {dbFile: "-", wantErr: true}, - "Error if UID_MIN is equal to UID_MAX": {uidMin: 1000, uidMax: 1000, wantErr: true}, - "Error if GID_MIN is equal to GID_MAX": {gidMin: 1000, gidMax: 1000, wantErr: true}, - "Error if UID range is too small": {uidMin: 1000, uidMax: 2000, wantErr: true}, + "Error_when_database_is_corrupted": {corruptedDbFile: true, wantErr: true}, + "Error_if_cacheDir_does_not_exist": {dbFile: "-", wantErr: true}, + "Error_if_UID_MIN_is_equal_to_UID_MAX": {uidMin: 1000, uidMax: 1000, wantErr: true}, + "Error_if_GID_MIN_is_equal_to_GID_MAX": {gidMin: 1000, gidMax: 1000, wantErr: true}, + "Error_if_UID_range_is_too_small": {uidMin: 1000, uidMax: 2000, wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -153,22 +153,22 @@ func TestUpdateUser(t *testing.T) { noOutput bool wantSameUID bool }{ - "Successfully update user": {groupsCase: "authd-group"}, - "Successfully update user updating local groups": {groupsCase: "mixed-groups-authd-first", localGroupsFile: "users_in_groups.group"}, - "UID does not change if user already exists": {userCase: "same-name-different-uid", dbFile: "one_user_and_group", wantSameUID: true}, - "GID does not change if group with same UGID exists": {groupsCase: "different-name-same-ugid", dbFile: "one_user_and_group"}, - "GID does not change if group with same name and empty UGID exists": {groupsCase: "authd-group", dbFile: "group-with-empty-UGID"}, - - "Error if user has no username": {userCase: "nameless", wantErr: true, noOutput: true}, - "Error if group has no name": {groupsCase: "nameless-group", wantErr: true, noOutput: true}, - "Error if group has conflicting gid": {groupsCase: "different-name-same-gid", dbFile: "one_user_and_group", wantErr: true, noOutput: true}, - "Error if group with same name but different UGID exists": {groupsCase: "authd-group", dbFile: "one_user_and_group", wantErr: true, noOutput: true}, - - "Error when updating local groups remove user from db": {groupsCase: "mixed-groups-gpasswd-fail", localGroupsFile: "gpasswdfail_in_deleted_group.group", wantErr: true}, - "Error when updating local groups remove user from db without touching other users": {dbFile: "multiple_users_and_groups", groupsCase: "mixed-groups-gpasswd-fail", localGroupsFile: "gpasswdfail_in_deleted_group.group", wantErr: true}, - "Error when updating local groups remove user from db even if already existed": {userCase: "user2", dbFile: "multiple_users_and_groups", groupsCase: "mixed-groups-gpasswd-fail", localGroupsFile: "gpasswdfail_in_deleted_group.group", wantErr: true}, - - "Error on invalid entry": {groupsCase: "authd-group", dbFile: "invalid_entry_in_userToGroups", localGroupsFile: "users_in_groups.group", wantErr: true, noOutput: true}, + "Successfully_update_user": {groupsCase: "authd-group"}, + "Successfully_update_user_updating_local_groups": {groupsCase: "mixed-groups-authd-first", localGroupsFile: "users_in_groups.group"}, + "UID_does_not_change_if_user_already_exists": {userCase: "same-name-different-uid", dbFile: "one_user_and_group", wantSameUID: true}, + "GID_does_not_change_if_group_with_same_UGID_exists": {groupsCase: "different-name-same-ugid", dbFile: "one_user_and_group"}, + "GID_does_not_change_if_group_with_same_name_and_empty_UGID_exists": {groupsCase: "authd-group", dbFile: "group-with-empty-UGID"}, + + "Error_if_user_has_no_username": {userCase: "nameless", wantErr: true, noOutput: true}, + "Error_if_group_has_no_name": {groupsCase: "nameless-group", wantErr: true, noOutput: true}, + "Error_if_group_has_conflicting_gid": {groupsCase: "different-name-same-gid", dbFile: "one_user_and_group", wantErr: true, noOutput: true}, + "Error_if_group_with_same_name_but_different_UGID_exists": {groupsCase: "authd-group", dbFile: "one_user_and_group", wantErr: true, noOutput: true}, + + "Error_when_updating_local_groups_remove_user_from_db": {groupsCase: "mixed-groups-gpasswd-fail", localGroupsFile: "gpasswdfail_in_deleted_group.group", wantErr: true}, + "Error_when_updating_local_groups_remove_user_from_db_without_touching_other_users": {dbFile: "multiple_users_and_groups", groupsCase: "mixed-groups-gpasswd-fail", localGroupsFile: "gpasswdfail_in_deleted_group.group", wantErr: true}, + "Error_when_updating_local_groups_remove_user_from_db_even_if_already_existed": {userCase: "user2", dbFile: "multiple_users_and_groups", groupsCase: "mixed-groups-gpasswd-fail", localGroupsFile: "gpasswdfail_in_deleted_group.group", wantErr: true}, + + "Error_on_invalid_entry": {groupsCase: "authd-group", dbFile: "invalid_entry_in_userToGroups", localGroupsFile: "users_in_groups.group", wantErr: true, noOutput: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -254,11 +254,11 @@ func TestBrokerForUser(t *testing.T) { wantErr bool wantErrType error }{ - "Successfully get broker for user": {username: "user1", dbFile: "multiple_users_and_groups", wantBrokerID: "broker-id"}, - "Return no broker but in cache if user has no broker yet": {username: "userwithoutbroker", dbFile: "multiple_users_and_groups", wantBrokerID: ""}, + "Successfully_get_broker_for_user": {username: "user1", dbFile: "multiple_users_and_groups", wantBrokerID: "broker-id"}, + "Return_no_broker_but_in_cache_if_user_has_no_broker_yet": {username: "userwithoutbroker", dbFile: "multiple_users_and_groups", wantBrokerID: ""}, - "Error if user does not exist": {username: "doesnotexist", dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, - "Error if db has invalid entry": {username: "user1", dbFile: "invalid_entry_in_userByName", wantErr: true}, + "Error_if_user_does_not_exist": {username: "doesnotexist", dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, + "Error_if_db_has_invalid_entry": {username: "user1", dbFile: "invalid_entry_in_userByName", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -290,10 +290,10 @@ func TestUpdateBrokerForUser(t *testing.T) { wantErr bool wantErrType error }{ - "Successfully update broker for user": {}, + "Successfully_update_broker_for_user": {}, - "Error if user does not exist": {username: "doesnotexist", wantErrType: cache.NoDataFoundError{}}, - "Error if db has invalid entry": {dbFile: "invalid_entry_in_userByName", wantErr: true}, + "Error_if_user_does_not_exist": {username: "doesnotexist", wantErrType: cache.NoDataFoundError{}}, + "Error_if_db_has_invalid_entry": {dbFile: "invalid_entry_in_userByName", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -337,15 +337,15 @@ func TestUserByIDAndName(t *testing.T) { wantErr bool wantErrType error }{ - "Successfully get user by ID": {uid: 1111, dbFile: "multiple_users_and_groups"}, - "Successfully get user by name": {username: "user1", dbFile: "multiple_users_and_groups"}, - "Successfully get temporary user by ID": {dbFile: "multiple_users_and_groups", isTempUser: true}, - "Successfully get temporary user by name": {username: "tempuser1", dbFile: "multiple_users_and_groups", isTempUser: true}, - - "Error if user does not exist - by ID": {uid: 0, dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, - "Error if user does not exist - by name": {username: "doesnotexist", dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, - "Error if db has invalid entry - by ID": {uid: 1111, dbFile: "invalid_entry_in_userByID", wantErr: true}, - "Error if db has invalid entry - by name": {username: "user1", dbFile: "invalid_entry_in_userByName", wantErr: true}, + "Successfully_get_user_by_ID": {uid: 1111, dbFile: "multiple_users_and_groups"}, + "Successfully_get_user_by_name": {username: "user1", dbFile: "multiple_users_and_groups"}, + "Successfully_get_temporary_user_by_ID": {dbFile: "multiple_users_and_groups", isTempUser: true}, + "Successfully_get_temporary_user_by_name": {username: "tempuser1", dbFile: "multiple_users_and_groups", isTempUser: true}, + + "Error_if_user_does_not_exist_-_by_ID": {uid: 0, dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, + "Error_if_user_does_not_exist_-_by_name": {username: "doesnotexist", dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, + "Error_if_db_has_invalid_entry_-_by_ID": {uid: 1111, dbFile: "invalid_entry_in_userByID", wantErr: true}, + "Error_if_db_has_invalid_entry_-_by_name": {username: "user1", dbFile: "invalid_entry_in_userByName", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -396,9 +396,9 @@ func TestAllUsers(t *testing.T) { wantErr bool wantErrType error }{ - "Successfully get all users": {dbFile: "multiple_users_and_groups"}, + "Successfully_get_all_users": {dbFile: "multiple_users_and_groups"}, - "Error if db has invalid entry": {dbFile: "invalid_entry_in_userByID", wantErr: true}, + "Error_if_db_has_invalid_entry": {dbFile: "invalid_entry_in_userByID", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -432,15 +432,15 @@ func TestGroupByIDAndName(t *testing.T) { wantErr bool wantErrType error }{ - "Successfully get group by ID": {gid: 11111, dbFile: "multiple_users_and_groups"}, - "Successfully get group by name": {groupname: "group1", dbFile: "multiple_users_and_groups"}, - "Successfully get temporary group by ID": {dbFile: "multiple_users_and_groups", isTempGroup: true}, - "Successfully get temporary group by name": {groupname: "tempgroup1", dbFile: "multiple_users_and_groups", isTempGroup: true}, - - "Error if group does not exist - by ID": {gid: 0, dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, - "Error if group does not exist - by name": {groupname: "doesnotexist", dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, - "Error if db has invalid entry - by ID": {gid: 11111, dbFile: "invalid_entry_in_groupByID", wantErr: true}, - "Error if db has invalid entry - by name": {groupname: "group1", dbFile: "invalid_entry_in_groupByName", wantErr: true}, + "Successfully_get_group_by_ID": {gid: 11111, dbFile: "multiple_users_and_groups"}, + "Successfully_get_group_by_name": {groupname: "group1", dbFile: "multiple_users_and_groups"}, + "Successfully_get_temporary_group_by_ID": {dbFile: "multiple_users_and_groups", isTempGroup: true}, + "Successfully_get_temporary_group_by_name": {groupname: "tempgroup1", dbFile: "multiple_users_and_groups", isTempGroup: true}, + + "Error_if_group_does_not_exist_-_by_ID": {gid: 0, dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, + "Error_if_group_does_not_exist_-_by_name": {groupname: "doesnotexist", dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, + "Error_if_db_has_invalid_entry_-_by_ID": {gid: 11111, dbFile: "invalid_entry_in_groupByID", wantErr: true}, + "Error_if_db_has_invalid_entry_-_by_name": {groupname: "group1", dbFile: "invalid_entry_in_groupByName", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -490,9 +490,9 @@ func TestAllGroups(t *testing.T) { wantErr bool wantErrType error }{ - "Successfully get all groups": {dbFile: "multiple_users_and_groups"}, + "Successfully_get_all_groups": {dbFile: "multiple_users_and_groups"}, - "Error if db has invalid entry": {dbFile: "invalid_entry_in_groupByID", wantErr: true}, + "Error_if_db_has_invalid_entry": {dbFile: "invalid_entry_in_groupByID", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -524,10 +524,10 @@ func TestShadowByName(t *testing.T) { wantErr bool wantErrType error }{ - "Successfully get shadow by name": {username: "user1", dbFile: "multiple_users_and_groups"}, + "Successfully_get_shadow_by_name": {username: "user1", dbFile: "multiple_users_and_groups"}, - "Error if shadow does not exist": {username: "doesnotexist", dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, - "Error if db has invalid entry": {username: "user1", dbFile: "invalid_entry_in_userByName", wantErr: true}, + "Error_if_shadow_does_not_exist": {username: "doesnotexist", dbFile: "multiple_users_and_groups", wantErrType: cache.NoDataFoundError{}}, + "Error_if_db_has_invalid_entry": {username: "user1", dbFile: "invalid_entry_in_userByName", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -557,9 +557,9 @@ func TestAllShadows(t *testing.T) { wantErr bool }{ - "Successfully get all users": {dbFile: "multiple_users_and_groups"}, + "Successfully_get_all_users": {dbFile: "multiple_users_and_groups"}, - "Error if db has invalid entry": {dbFile: "invalid_entry_in_userByID", wantErr: true}, + "Error_if_db_has_invalid_entry": {dbFile: "invalid_entry_in_userByID", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/internal/users/tempentries/groups_test.go b/internal/users/tempentries/groups_test.go index 4dcc760cd..78e3a5b0d 100644 --- a/internal/users/tempentries/groups_test.go +++ b/internal/users/tempentries/groups_test.go @@ -20,12 +20,12 @@ func TestRegisterGroup(t *testing.T) { wantErr bool }{ - "Successfully register a new group": {}, - "Successfully register a group if the first generated GID is already in use": { + "Successfully_register_a_new_group": {}, + "Successfully_register_a_group_if_the_first_generated_GID_is_already_in_use": { gidsToGenerate: []uint32{0, gidToGenerate}, // GID 0 (root) always exists }, - "Error when name is already in use": {groupName: "root", wantErr: true}, + "Error_when_name_is_already_in_use": {groupName: "root", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { @@ -77,17 +77,17 @@ func TestGroupByIDAndName(t *testing.T) { wantErr bool }{ - "Successfully get a group by ID": {registerGroup: true}, - "Successfully get a group by name": {registerGroup: true, byName: true}, + "Successfully_get_a_group_by_ID": {registerGroup: true}, + "Successfully_get_a_group_by_name": {registerGroup: true, byName: true}, - "Error when group is not registered - GroupByID": {wantErr: true}, - "Error when group is not registered - GroupByName": {byName: true, wantErr: true}, - "Error when group is already removed - GroupByID": { + "Error_when_group_is_not_registered_-_GroupByID": {wantErr: true}, + "Error_when_group_is_not_registered_-_GroupByName": {byName: true, wantErr: true}, + "Error_when_group_is_already_removed_-_GroupByID": { registerGroup: true, groupAlreadyRemoved: true, wantErr: true, }, - "Error when group is already removed - GroupByName": { + "Error_when_group_is_already_removed_-_GroupByName": { registerGroup: true, groupAlreadyRemoved: true, byName: true, diff --git a/internal/users/tempentries/preauth_test.go b/internal/users/tempentries/preauth_test.go index dd2b93146..67dc89e14 100644 --- a/internal/users/tempentries/preauth_test.go +++ b/internal/users/tempentries/preauth_test.go @@ -22,13 +22,13 @@ func TestPreAuthUser(t *testing.T) { wantErr bool }{ - "Successfully register a pre-auth user": {}, - "Successfully register a pre-auth user if the first generated UID is already in use": { + "Successfully_register_a_pre-auth_user": {}, + "Successfully_register_a_pre-auth_user_if_the_first_generated_UID_is_already_in_use": { uidsToGenerate: []uint32{0, uidToGenerate}, // UID 0 (root) always exists }, - "No error when registering a pre-auth user with the same name": {registerTwice: true}, + "No_error_when_registering_a_pre-auth_user_with_the_same_name": {registerTwice: true}, - "Error when maximum number of pre-auth users is reached": {maxUsers: true, wantErr: true}, + "Error_when_maximum_number_of_pre-auth_users_is_reached": {maxUsers: true, wantErr: true}, } for name, tc := range tests { @@ -90,10 +90,10 @@ func TestPreAuthUserByIDAndName(t *testing.T) { wantErr bool }{ - "Successfully get a user by ID and name": {registerUser: true}, + "Successfully_get_a_user_by_ID_and_name": {registerUser: true}, - "Error when user is not registered": {wantErr: true}, - "Error when user is already removed": {registerUser: true, userAlreadyRemoved: true, wantErr: true}, + "Error_when_user_is_not_registered": {wantErr: true}, + "Error_when_user_is_already_removed": {registerUser: true, userAlreadyRemoved: true, wantErr: true}, } for name, tc := range tests { diff --git a/internal/users/tempentries/tempentries_test.go b/internal/users/tempentries/tempentries_test.go index a70b3c175..f90a842bf 100644 --- a/internal/users/tempentries/tempentries_test.go +++ b/internal/users/tempentries/tempentries_test.go @@ -24,22 +24,22 @@ func TestRegisterUser(t *testing.T) { wantErr bool }{ - "Successfully register a new user": {}, - "Successfully register a user if the first generated UID is already in use": { + "Successfully_register_a_new_user": {}, + "Successfully_register_a_user_if_the_first_generated_UID_is_already_in_use": { uidsToGenerate: []uint32{0, uidToGenerate}, // UID 0 (root) always exists }, - "Successfully register a user if the pre-auth user already exists": { + "Successfully_register_a_user_if_the_pre-auth_user_already_exists": { replacesPreAuthUser: true, uidsToGenerate: []uint32{}, // No UID generation needed }, - "Error when name is already in use": {userName: "root", wantErr: true}, - "Error when pre-auth user already exists and name is not unique": { + "Error_when_name_is_already_in_use": {userName: "root", wantErr: true}, + "Error_when_pre-auth_user_already_exists_and_name_is_not_unique": { replacesPreAuthUser: true, userName: "root", wantErr: true, }, - "Error when pre-auth UID is not unique": { + "Error_when_pre-auth_UID_is_not_unique": { replacesPreAuthUser: true, preAuthUIDAlreadyExists: true, wantErr: true, @@ -107,17 +107,17 @@ func TestUserByIDAndName(t *testing.T) { wantErr bool }{ - "Successfully get a user by ID": {registerUser: true}, - "Successfully get a user by name": {registerUser: true, byName: true}, + "Successfully_get_a_user_by_ID": {registerUser: true}, + "Successfully_get_a_user_by_name": {registerUser: true, byName: true}, - "Error when user is not registered - UserByID": {wantErr: true}, - "Error when user is not registered - UserByName": {byName: true, wantErr: true}, - "Error when user is already removed - UserByID": { + "Error_when_user_is_not_registered_-_UserByID": {wantErr: true}, + "Error_when_user_is_not_registered_-_UserByName": {byName: true, wantErr: true}, + "Error_when_user_is_already_removed_-_UserByID": { registerUser: true, userAlreadyRemoved: true, wantErr: true, }, - "Error when user is already removed - UserByName": { + "Error_when_user_is_already_removed_-_UserByName": { registerUser: true, userAlreadyRemoved: true, byName: true, diff --git a/nss/integration-tests/integration_test.go b/nss/integration-tests/integration_test.go index 2d407a8a2..ba814bb6c 100644 --- a/nss/integration-tests/integration_test.go +++ b/nss/integration-tests/integration_test.go @@ -55,51 +55,51 @@ func TestIntegration(t *testing.T) { wantStatus int }{ - "Get all entries from passwd": {db: "passwd"}, - "Get all entries from group": {db: "group"}, - "Get all entries from shadow if considered root": {db: "shadow"}, + "Get_all_entries_from_passwd": {db: "passwd"}, + "Get_all_entries_from_group": {db: "group"}, + "Get_all_entries_from_shadow_if_considered_root": {db: "shadow"}, - "Get entry from passwd by name": {db: "passwd", key: "user1"}, - "Get entry from group by name": {db: "group", key: "group1"}, - "Get entry from shadow by name if considered root": {db: "shadow", key: "user1"}, + "Get_entry_from_passwd_by_name": {db: "passwd", key: "user1"}, + "Get_entry_from_group_by_name": {db: "group", key: "group1"}, + "Get_entry_from_shadow_by_name_if_considered_root": {db: "shadow", key: "user1"}, - "Get entry from passwd by id": {db: "passwd", key: "1111"}, - "Get entry from group by id": {db: "group", key: "11111"}, + "Get_entry_from_passwd_by_id": {db: "passwd", key: "1111"}, + "Get_entry_from_group_by_id": {db: "group", key: "11111"}, - "Check user with broker if not found in cache": {db: "passwd", key: "user-pre-check", shouldPreCheck: true}, + "Check_user_with_broker_if_not_found_in_cache": {db: "passwd", key: "user-pre-check", shouldPreCheck: true}, // Even though those are "error" cases, the getent command won't fail when trying to list content of a service. - "Returns empty when getting all entries from shadow if regular user": {db: "shadow", currentUserNotRoot: true}, + "Returns_empty_when_getting_all_entries_from_shadow_if_regular_user": {db: "shadow", currentUserNotRoot: true}, - "Returns empty when getting all entries from passwd and daemon is not available": {db: "passwd", noDaemon: true}, - "Returns empty when getting all entries from group and daemon is not available": {db: "group", noDaemon: true}, - "Returns empty when getting all entries from shadow and daemon is not available": {db: "shadow", noDaemon: true}, + "Returns_empty_when_getting_all_entries_from_passwd_and_daemon_is_not_available": {db: "passwd", noDaemon: true}, + "Returns_empty_when_getting_all_entries_from_group_and_daemon_is_not_available": {db: "group", noDaemon: true}, + "Returns_empty_when_getting_all_entries_from_shadow_and_daemon_is_not_available": {db: "shadow", noDaemon: true}, /* Error cases */ // We can't assert on the returned error type since the error returned by getent will always be 2 (i.e. Not Found), even though the library returns other types. - "Error when getting all entries from passwd and database is corrupted": {db: "passwd", cacheDB: "invalid_entry_in_userByID", wantSecondCall: true}, - "Error when getting all entries from group and database is corrupted": {db: "group", cacheDB: "invalid_entry_in_groupByID", wantSecondCall: true}, - "Error when getting all entries from shadow and database is corrupted": {db: "shadow", cacheDB: "invalid_entry_in_userByID", wantSecondCall: true}, + "Error_when_getting_all_entries_from_passwd_and_database_is_corrupted": {db: "passwd", cacheDB: "invalid_entry_in_userByID", wantSecondCall: true}, + "Error_when_getting_all_entries_from_group_and_database_is_corrupted": {db: "group", cacheDB: "invalid_entry_in_groupByID", wantSecondCall: true}, + "Error_when_getting_all_entries_from_shadow_and_database_is_corrupted": {db: "shadow", cacheDB: "invalid_entry_in_userByID", wantSecondCall: true}, - "Error when getting shadow by name if regular user": {db: "shadow", key: "user1", currentUserNotRoot: true, wantStatus: codeNotFound}, + "Error_when_getting_shadow_by_name_if_regular_user": {db: "shadow", key: "user1", currentUserNotRoot: true, wantStatus: codeNotFound}, - "Error when getting passwd by name and entry does not exist": {db: "passwd", key: "doesnotexit", wantStatus: codeNotFound}, - "Error when getting passwd by name entry exists in broker but precheck is disabled": {db: "passwd", key: "user-pre-check", wantStatus: codeNotFound}, - "Error when getting group by name and entry does not exist": {db: "group", key: "doesnotexit", wantStatus: codeNotFound}, - "Error when getting shadow by name and entry does not exist": {db: "shadow", key: "doesnotexit", wantStatus: codeNotFound}, + "Error_when_getting_passwd_by_name_and_entry_does_not_exist": {db: "passwd", key: "doesnotexit", wantStatus: codeNotFound}, + "Error_when_getting_passwd_by_name_entry_exists_in_broker_but_precheck_is_disabled": {db: "passwd", key: "user-pre-check", wantStatus: codeNotFound}, + "Error_when_getting_group_by_name_and_entry_does_not_exist": {db: "group", key: "doesnotexit", wantStatus: codeNotFound}, + "Error_when_getting_shadow_by_name_and_entry_does_not_exist": {db: "shadow", key: "doesnotexit", wantStatus: codeNotFound}, - "Error when getting passwd by id and entry does not exist": {db: "passwd", key: "404", wantStatus: codeNotFound}, - "Error when getting group by id and entry does not exist": {db: "group", key: "404", wantStatus: codeNotFound}, + "Error_when_getting_passwd_by_id_and_entry_does_not_exist": {db: "passwd", key: "404", wantStatus: codeNotFound}, + "Error_when_getting_group_by_id_and_entry_does_not_exist": {db: "group", key: "404", wantStatus: codeNotFound}, - "Error when getting passwd by name and daemon is not available": {db: "passwd", key: "user1", noDaemon: true, wantStatus: codeNotFound}, - "Error when getting group by name and daemon is not available": {db: "group", key: "group1", noDaemon: true, wantStatus: codeNotFound}, - "Error when getting shadow by name and daemon is not available": {db: "shadow", key: "user1", noDaemon: true, wantStatus: codeNotFound}, + "Error_when_getting_passwd_by_name_and_daemon_is_not_available": {db: "passwd", key: "user1", noDaemon: true, wantStatus: codeNotFound}, + "Error_when_getting_group_by_name_and_daemon_is_not_available": {db: "group", key: "group1", noDaemon: true, wantStatus: codeNotFound}, + "Error_when_getting_shadow_by_name_and_daemon_is_not_available": {db: "shadow", key: "user1", noDaemon: true, wantStatus: codeNotFound}, - "Error when getting passwd by id and daemon is not available": {db: "passwd", key: "1111", noDaemon: true, wantStatus: codeNotFound}, - "Error when getting group by id and daemon is not available": {db: "group", key: "11111", noDaemon: true, wantStatus: codeNotFound}, + "Error_when_getting_passwd_by_id_and_daemon_is_not_available": {db: "passwd", key: "1111", noDaemon: true, wantStatus: codeNotFound}, + "Error_when_getting_group_by_id_and_daemon_is_not_available": {db: "group", key: "11111", noDaemon: true, wantStatus: codeNotFound}, /* Special cases */ - "Do not query the cache when user is pam_unix_non_existent": {db: "passwd", key: "pam_unix_non_existent:", cacheDB: "pam_unix_non_existent", wantStatus: codeNotFound}, + "Do_not_query_the_cache_when_user_is_pam_unix_non_existent": {db: "passwd", key: "pam_unix_non_existent:", cacheDB: "pam_unix_non_existent", wantStatus: codeNotFound}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/pam/integration-tests/cli_test.go b/pam/integration-tests/cli_test.go index efc32a70d..53b9a0a4b 100644 --- a/pam/integration-tests/cli_test.go +++ b/pam/integration-tests/cli_test.go @@ -41,35 +41,35 @@ func TestCLIAuthenticate(t *testing.T) { wantLocalGroups bool stopDaemonAfter time.Duration }{ - "Authenticate user successfully": { + "Authenticate_user_successfully": { tape: "simple_auth", tapeVariables: map[string]string{"AUTHD_SIMPLE_AUTH_TAPE_USER": "user1"}, }, - "Authenticate user successfully with preset user": { + "Authenticate_user_successfully_with_preset_user": { tape: "simple_auth_with_preset_user", clientOptions: clientOptions{PamUser: "user-integration-simple-preset"}, }, - "Authenticate user successfully with invalid connection timeout": { + "Authenticate_user_successfully_with_invalid_connection_timeout": { tape: "simple_auth", tapeVariables: map[string]string{ "AUTHD_SIMPLE_AUTH_TAPE_USER": "user-integration-invalid-timeout", }, clientOptions: clientOptions{PamTimeout: "invalid"}, }, - "Authenticate user successfully after trying empty user": { + "Authenticate_user_successfully_after_trying_empty_user": { tape: "simple_auth_empty_user", }, - "Authenticate user with mfa": { + "Authenticate_user_with_mfa": { tape: "mfa_auth", }, - "Authenticate user with form mode with button": { + "Authenticate_user_with_form_mode_with_button": { tape: "form_with_button", }, - "Authenticate user with qr code": { + "Authenticate_user_with_qr_code": { tape: "qr_code", clientOptions: clientOptions{PamUser: "user-integration-qr-code"}, }, - "Authenticate user with qr code in a TTY": { + "Authenticate_user_with_qr_code_in_a_TTY": { tape: "qr_code", tapeSettings: []tapeSetting{{vhsHeight, 800}}, clientOptions: clientOptions{ @@ -77,7 +77,7 @@ func TestCLIAuthenticate(t *testing.T) { Term: "linux", }, }, - "Authenticate user with qr code in a TTY session": { + "Authenticate_user_with_qr_code_in_a_TTY_session": { tape: "qr_code", tapeSettings: []tapeSetting{{vhsHeight, 800}}, clientOptions: clientOptions{ @@ -85,7 +85,7 @@ func TestCLIAuthenticate(t *testing.T) { Term: "xterm-256color", SessionType: "tty", }, }, - "Authenticate user with qr code in screen": { + "Authenticate_user_with_qr_code_in_screen": { tape: "qr_code", tapeSettings: []tapeSetting{{vhsHeight, 800}}, clientOptions: clientOptions{ @@ -93,84 +93,84 @@ func TestCLIAuthenticate(t *testing.T) { Term: "screen", }, }, - "Authenticate user with qr code after many regenerations": { + "Authenticate_user_with_qr_code_after_many_regenerations": { tape: "qr_code_quick_regenerate", tapeSettings: []tapeSetting{ {vhsHeight, 800}, {vhsWaitTimeout, 15 * time.Second}, }, }, - "Authenticate user and reset password while enforcing policy": { + "Authenticate_user_and_reset_password_while_enforcing_policy": { tape: "mandatory_password_reset", }, - "Authenticate user with mfa and reset password while enforcing policy": { + "Authenticate_user_with_mfa_and_reset_password_while_enforcing_policy": { tape: "mfa_reset_pwquality_auth", }, - "Authenticate user and offer password reset": { + "Authenticate_user_and_offer_password_reset": { tape: "optional_password_reset_skip", }, - "Authenticate user switching auth mode": { + "Authenticate_user_switching_auth_mode": { tape: "switch_auth_mode", }, - "Authenticate user switching username": { + "Authenticate_user_switching_username": { tape: "switch_username", }, - "Authenticate user switching to local broker": { + "Authenticate_user_switching_to_local_broker": { tape: "switch_local_broker", tapeSettings: []tapeSetting{{vhsHeight, 800}}, }, - "Authenticate user and add it to local group": { + "Authenticate_user_and_add_it_to_local_group": { tape: "local_group", wantLocalGroups: true, }, - "Authenticate with warnings on unsupported arguments": { + "Authenticate_with_warnings_on_unsupported_arguments": { tape: "simple_auth_with_unsupported_args", }, - "Remember last successful broker and mode": { + "Remember_last_successful_broker_and_mode": { tape: "remember_broker_and_mode", }, - "Autoselect local broker for local user": { + "Autoselect_local_broker_for_local_user": { tape: "local_user", }, - "Autoselect local broker for local user preset": { + "Autoselect_local_broker_for_local_user_preset": { tape: "local_user_preset", clientOptions: clientOptions{PamUser: "root"}, }, - "Prevent user from switching username": { + "Prevent_user_from_switching_username": { tape: "switch_preset_username", clientOptions: clientOptions{PamUser: "user-integration-pam-preset"}, }, - "Deny authentication if current user is not considered as root": { + "Deny_authentication_if_current_user_is_not_considered_as_root": { tape: "not_root", currentUserNotRoot: true, }, - "Deny authentication if max attempts reached": { + "Deny_authentication_if_max_attempts_reached": { tape: "max_attempts", }, - "Deny authentication if user does not exist": { + "Deny_authentication_if_user_does_not_exist": { tape: "unexistent_user", tapeSettings: []tapeSetting{{vhsHeight, 800}}, }, - "Deny authentication if newpassword does not match required criteria": { + "Deny_authentication_if_newpassword_does_not_match_required_criteria": { tape: "bad_password", }, - "Exit authd if local broker is selected": { + "Exit_authd_if_local_broker_is_selected": { tape: "local_broker", tapeSettings: []tapeSetting{{vhsHeight, 800}}, }, - "Exit authd if user sigints": { + "Exit_authd_if_user_sigints": { tape: "sigint", }, - "Exit if authd is stopped": { + "Exit_if_authd_is_stopped": { tape: "authd_stopped", stopDaemonAfter: sleepDuration(defaultSleepValues[authdSleepLong] * 5), }, - "Error if cannot connect to authd": { + "Error_if_cannot_connect_to_authd": { tape: "connection_error", socketPath: "/some-path/not-existent-socket", }, @@ -242,47 +242,47 @@ func TestCLIChangeAuthTok(t *testing.T) { currentUserNotRoot bool }{ - "Change password successfully and authenticate with new one": { + "Change_password_successfully_and_authenticate_with_new_one": { tape: "passwd_simple", tapeVariables: map[string]string{ "AUTHD_TEST_TAPE_LOGIN_COMMAND": fmt.Sprintf( tapeBaseCommand, pam_test.RunnerActionLogin, socketPathEnv), }, }, - "Change passwd after MFA auth": { + "Change_passwd_after_MFA_auth": { tape: "passwd_mfa", }, - "Retry if new password is rejected by broker": { + "Retry_if_new_password_is_rejected_by_broker": { tape: "passwd_rejected", }, - "Retry if new password is same of previous": { + "Retry_if_new_password_is_same_of_previous": { tape: "passwd_not_changed", }, - "Retry if password confirmation is not the same": { + "Retry_if_password_confirmation_is_not_the_same": { tape: "passwd_not_confirmed", }, - "Retry if new password does not match quality criteria": { + "Retry_if_new_password_does_not_match_quality_criteria": { tape: "passwd_bad_password", }, - "Prevent change password if auth fails": { + "Prevent_change_password_if_auth_fails": { tape: "passwd_auth_fail", }, - "Prevent change password if user does not exist": { + "Prevent_change_password_if_user_does_not_exist": { tape: "passwd_unexistent_user", tapeSettings: []tapeSetting{{vhsHeight, 800}}, }, - "Prevent change password if current user is not root as can not authenticate": { + "Prevent_change_password_if_current_user_is_not_root_as_can_not_authenticate": { tape: "passwd_not_root", currentUserNotRoot: true, }, - "Exit authd if local broker is selected": { + "Exit_authd_if_local_broker_is_selected": { tape: "passwd_local_broker", tapeSettings: []tapeSetting{{vhsHeight, 800}}, }, - "Exit authd if user sigints": { + "Exit_authd_if_user_sigints": { tape: "passwd_sigint", }, } diff --git a/pam/integration-tests/exec_test.go b/pam/integration-tests/exec_test.go index f20cdff3a..eb04d544e 100644 --- a/pam/integration-tests/exec_test.go +++ b/pam/integration-tests/exec_test.go @@ -41,22 +41,22 @@ func TestExecModule(t *testing.T) { wantError error }{ // Error cases - "Error on no arguments": { + "Error_on_no_arguments": { wantError: pam.ErrModuleUnknown, }, - "Error on empty executable parameter": { + "Error_on_empty_executable_parameter": { moduleArgs: []string{""}, wantError: pam.ErrModuleUnknown, }, - "Error on non existent executable parameter": { + "Error_on_non_existent_executable_parameter": { moduleArgs: []string{"/non-existent/file"}, wantError: pam.ErrModuleUnknown, }, - "Error on non executable parameter": { + "Error_on_non_executable_parameter": { moduleArgs: execModuleSources, wantError: pam.ErrModuleUnknown, }, - "Error on not runnable parameter": { + "Error_on_not_runnable_parameter": { moduleArgs: []string{filepath.Join(testutils.ProjectRoot())}, wantError: pam.ErrSystem, }, @@ -82,19 +82,19 @@ func TestExecModule(t *testing.T) { rawModuleArgs []string wantError error }{ - "SetGet Item": { + "SetGet_Item": { methodCalls: []cliMethodCall{ {m: "SetItem", args: []any{pam.Rhost, "some-rhost-value"}, r: []any{nil}}, {m: "GetItem", args: []any{pam.Rhost}, r: []any{"some-rhost-value", nil}}, }, }, - "SetGet Item handling errors": { + "SetGet_Item_handling_errors": { methodCalls: []cliMethodCall{ {m: "SetItem", args: []any{pam.Item(-1), "some-value"}, r: []any{pam.ErrBadItem}}, {m: "GetItem", args: []any{pam.Item(-1)}, r: []any{"", pam.ErrBadItem}}, }, }, - "SetGet Env": { + "SetGet_Env": { methodCalls: []cliMethodCall{ {m: "PutEnv", args: []any{"FooEnv=bar"}, r: []any{nil}}, {m: "GetEnv", args: []any{"FooEnv"}, r: []any{"bar"}}, @@ -109,7 +109,7 @@ func TestExecModule(t *testing.T) { {m: "GetEnv", args: []any{"FooEnv"}}, }, }, - "SetGet Data": { + "SetGet_Data": { methodCalls: []cliMethodCall{ {m: "SetData", args: []any{"FooData", "bar"}, r: []any{nil}}, {m: "GetData", args: []any{"FooData"}, r: []any{"bar", nil}}, @@ -123,12 +123,12 @@ func TestExecModule(t *testing.T) { {m: "GetData", args: []any{"FooData"}, r: []any{nil, nil}}, }, }, - "GetEnvList empty": { + "GetEnvList_empty": { methodCalls: []cliMethodCall{ {m: "GetEnvList", r: []any{map[string]string{}, nil}}, }, }, - "GetEnvList populated": { + "GetEnvList_populated": { methodCalls: []cliMethodCall{ {m: "PutEnv", args: []any{"Env=value"}}, {m: "PutEnv", args: []any{"Env2=value2"}}, @@ -143,27 +143,27 @@ func TestExecModule(t *testing.T) { }, // Error cases - "Error providing invalid variant argument": { + "Error_providing_invalid_variant_argument": { rawModuleArgs: []string{"$not_A-variant Action"}, wantError: pam_test.ErrInvalidArguments, }, - "Error providing no action": { + "Error_providing_no_action": { rawModuleArgs: []string{dbus.MakeVariant(map[string]dbus.Variant{}).String()}, wantError: pam_test.ErrInvalidMethod, }, - "Error providing invalid action type": { + "Error_providing_invalid_action_type": { rawModuleArgs: []string{dbus.MakeVariant( map[string]dbus.Variant{"act": dbus.MakeVariant([]int{1, 2, 3})}, ).String()}, wantError: pam_test.ErrInvalidMethod, }, - "Error when not providing arguments": { + "Error_when_not_providing_arguments": { rawModuleArgs: []string{dbus.MakeVariant( map[string]dbus.Variant{"act": dbus.MakeVariant("SetItem")}, ).String()}, wantError: pam_test.ErrInvalidArguments, }, - "Error when providing no arguments": { + "Error_when_providing_no_arguments": { rawModuleArgs: []string{dbus.MakeVariant( map[string]dbus.Variant{ "act": dbus.MakeVariant("SetItem"), @@ -172,7 +172,7 @@ func TestExecModule(t *testing.T) { ).String()}, wantError: pam_test.ErrInvalidArguments, }, - "Error providing invalid arguments type": { + "Error_providing_invalid_arguments_type": { rawModuleArgs: []string{dbus.MakeVariant( map[string]dbus.Variant{ "act": dbus.MakeVariant("GetItem"), @@ -181,53 +181,53 @@ func TestExecModule(t *testing.T) { ).String()}, wantError: pam_test.ErrInvalidArguments, }, - "Error when providing empty arguments": { + "Error_when_providing_empty_arguments": { methodCalls: []cliMethodCall{{m: "SetItem", args: []any{}}}, wantError: pam_test.ErrInvalidArguments, }, - "Error when not providing enough arguments": { + "Error_when_not_providing_enough_arguments": { methodCalls: []cliMethodCall{{m: "SetItem", args: []any{pam.User}}}, wantError: pam_test.ErrInvalidArguments, }, - "Error when providing empty return values": { + "Error_when_providing_empty_return_values": { methodCalls: []cliMethodCall{{m: "SetItem", args: []any{pam.User, "an-user"}, r: []any{}}}, wantError: pam_test.ErrReturnMismatch, }, - "Error when not providing enough return values": { + "Error_when_not_providing_enough_return_values": { methodCalls: []cliMethodCall{{m: "GetItem", args: []any{pam.User}, r: []any{}}}, wantError: pam_test.ErrReturnMismatch, }, - "Error when calling unknown method": { + "Error_when_calling_unknown_method": { methodCalls: []cliMethodCall{{m: "ThisMethodDoesNotExist"}}, wantError: pam_test.ErrInvalidMethod, }, - "Error when argument types do not match arguments": { + "Error_when_argument_types_do_not_match_arguments": { methodCalls: []cliMethodCall{{m: "SetItem", args: []any{"an-item", "value"}}}, wantError: pam_test.ErrArgumentTypeMismatch, }, - "Error when return values types do not match expected": { + "Error_when_return_values_types_do_not_match_expected": { methodCalls: []cliMethodCall{ {m: "GetItem", args: []any{pam.Item(-1)}, r: []any{"", "should have been an error"}}, }, wantError: pam_test.ErrReturnMismatch, }, - "Error when trying to compare an unexpected variant value": { + "Error_when_trying_to_compare_an_unexpected_variant_value": { methodCalls: []cliMethodCall{{m: "GetEnvList", r: []any{"", nil}}}, wantError: pam_test.ErrReturnMismatch, }, - "Error when trying to compare a not-matching variant value": { + "Error_when_trying_to_compare_a_not-matching_variant_value": { methodCalls: []cliMethodCall{{m: "GetEnvList", r: []any{"string", nil}}}, wantError: pam_test.ErrReturnMismatch, }, - "Error when getting not-available user data": { + "Error_when_getting_not-available_user_data": { methodCalls: []cliMethodCall{{m: "GetData", args: []any{"NotAvailable"}}}, wantError: pam.ErrNoModuleData, }, - "Error when client fails panicking": { + "Error_when_client_fails_panicking": { methodCalls: []cliMethodCall{{m: "SimulateClientPanic", args: []any{"Client panicked! (As expected)"}}}, wantError: pam.ErrSymbol, }, - "Error when client fails because an unhandled error": { + "Error_when_client_fails_because_an_unhandled_error": { methodCalls: []cliMethodCall{{m: "SimulateClientError", args: []any{"Client error!"}}}, wantError: pam.ErrSystem, }, @@ -249,9 +249,9 @@ func TestExecModule(t *testing.T) { actionFlags := map[string]struct { flags pam.Flags }{ - "No flags set": {}, - "Silent flag set": {flags: pam.Silent}, - "Silent and RefreshCred flag set": {flags: pam.Silent | pam.RefreshCred}, + "No_flags_set": {}, + "Silent_flag_set": {flags: pam.Silent}, + "Silent_and_RefreshCred_flag_set": {flags: pam.Silent | pam.RefreshCred}, } for name, tc := range actionFlags { t.Run("Flags "+name, func(t *testing.T) { @@ -280,7 +280,7 @@ func TestExecModule(t *testing.T) { actionArgs := map[string]struct { moduleArgs []string }{ - "Do not deadlock if invalid log path is provided": { + "Do_not_deadlock_if_invalid_log_path_is_provided": { []string{"--exec-log", "/not-existent/file-path.log"}, }, } @@ -308,36 +308,36 @@ func TestExecModule(t *testing.T) { wantGetError error wantSetError error }{ - "Set user": { + "Set_user": { item: pam.User, value: ptrValue("an user"), }, - "Returns empty when getting an unset user": { + "Returns_empty_when_getting_an_unset_user": { item: pam.User, wantValue: ptrValue(""), }, - "Returns the user when getting a preset user": { + "Returns_the_user_when_getting_a_preset_user": { item: pam.User, user: "preset PAM user", wantValue: ptrValue("preset PAM user"), }, - "Setting and getting an user": { + "Setting_and_getting_an_user": { item: pam.User, value: ptrValue("the-user"), wantValue: ptrValue("the-user"), }, - "Getting the preset service name": { + "Getting_the_preset_service_name": { item: pam.Service, wantValue: ptrValue(execServiceName), }, // Error cases - "Error when setting invalid item": { + "Error_when_setting_invalid_item": { item: pam.Item(-1), value: ptrValue("some value"), wantSetError: pam.ErrBadItem, }, - "Error when getting invalid item": { + "Error_when_getting_invalid_item": { item: pam.Item(-1), wantGetError: pam.ErrBadItem, wantValue: ptrValue(""), @@ -391,32 +391,32 @@ func TestExecModule(t *testing.T) { wantValue *string wantPutError error }{ - "Put var": { + "Put_var": { env: "AN_ENV", value: ptrValue("value"), }, - "Unset a not-previously set value": { + "Unset_a_not-previously_set_value": { env: "NEVER_SET_ENV", wantPutError: pam.ErrBadItem, wantValue: ptrValue(""), }, - "Unset a preset value": { + "Unset_a_preset_value": { presetValues: map[string]string{"PRESET_ENV": "hey!"}, env: "PRESET_ENV", wantValue: ptrValue(""), }, - "Changes a preset var": { + "Changes_a_preset_var": { presetValues: map[string]string{"PRESET_ENV": "hey!"}, env: "PRESET_ENV", value: ptrValue("hello!"), wantValue: ptrValue("hello!"), }, - "Get an unset env": { + "Get_an_unset_env": { skipPut: true, env: "AN_UNSET_ENV", wantValue: ptrValue(""), }, - "Gets an invalid env name": { + "Gets_an_invalid_env_name": { env: "", value: ptrValue("Invalid Value"), wantValue: ptrValue(""), @@ -424,7 +424,7 @@ func TestExecModule(t *testing.T) { }, // Error cases - "Error when putting an invalid env name": { + "Error_when_putting_an_invalid_env_name": { env: "", value: ptrValue("Invalid Value"), wantPutError: pam.ErrBadItem, @@ -518,26 +518,26 @@ func TestExecModule(t *testing.T) { wantSetError error wantGetError error }{ - "Sets and gets data": { + "Sets_and_gets_data": { presetData: map[string]any{"some-data": []string{"hey! That's", "true"}}, key: "data", data: []string{"hey! That's", "true"}, wantData: []string{"hey! That's", "true"}, }, - "Gets previously set data": { + "Gets_previously_set_data": { presetData: map[string]any{"some-old-data": []int{3, 2, 1}}, key: "some-old-data", skipSet: true, wantData: []int{3, 2, 1}, }, - "Data can be nil": { + "Data_can_be_nil": { // This is actually a libpam issue, but we should respect that for now // See: https://github.com/linux-pam/linux-pam/pull/780 data: nil, key: "nil-data", wantData: nil, }, - "Set replaces data": { + "Set_replaces_data": { presetData: map[string]any{"some-data": []string{"hey! That's", "true"}}, key: "some-data", data: []map[string]string{ @@ -549,7 +549,7 @@ func TestExecModule(t *testing.T) { {"foo": "bar"}, }, }, - "No error when getting data that has been removed": { + "No_error_when_getting_data_that_has_been_removed": { presetData: map[string]any{"some-data": []string{"hey! That's", "true"}}, key: "some-data", data: nil, @@ -557,7 +557,7 @@ func TestExecModule(t *testing.T) { }, // Error cases - "Error when getting data that has never been set": { + "Error_when_getting_data_that_has_never_been_set": { skipSet: true, key: "not set", wantGetError: pam.ErrNoModuleData, @@ -620,20 +620,20 @@ func TestExecModule(t *testing.T) { wantError error wantExitError error }{ - "Messages with info style are handled by conversation": { + "Messages_with_info_style_are_handled_by_conversation": { prompt: "This is an info message!", convStyle: pam.TextInfo, }, - "Messages with error style are handled by conversation": { + "Messages_with_error_style_are_handled_by_conversation": { prompt: "This is an error message!", convStyle: pam.ErrorMsg, }, - "Messages with echo on style are handled by conversation": { + "Messages_with_echo_on_style_are_handled_by_conversation": { prompt: "This is an echo on message!", convStyle: pam.PromptEchoOn, want: "I'm handling it perfectly!", }, - "Conversation prompt can be formatted": { + "Conversation_prompt_can_be_formatted": { promptFormat: "Sending some %s, right? %v - But that's %v or %d?", promptFormatArgs: []interface{}{"info", true, nil, 123}, convStyle: pam.PromptEchoOff, @@ -641,31 +641,31 @@ func TestExecModule(t *testing.T) { }, // Error cases - "Error if no conversation handler is set": { + "Error_if_no_conversation_handler_is_set": { convHandler: ptrValue(pam.ConversationFunc(nil)), wantError: pam.ErrConv, }, - "Error if the conversation handler fails": { + "Error_if_the_conversation_handler_fails": { prompt: "Tell me your secret!", convStyle: pam.PromptEchoOff, convError: pam.ErrBuf, wantError: pam.ErrConv, }, - "Error when conversation uses binary content style": { + "Error_when_conversation_uses_binary_content_style": { prompt: "I am a binary content\xff!", convStyle: pam.BinaryPrompt, convError: pam.ErrConv, wantError: pam.ErrConv, convShouldNotBeCalled: true, }, - "Error when when parsing returned response fails": { + "Error_when_when_parsing_returned_response_fails": { prompt: "Hello!", convStyle: pam.PromptEchoOn, want: "Hey, hey!", stringResponse: "Hey, hey!", wantExitError: pam_test.ErrReturnMismatch, }, - "Error when when parsing returned value style fails": { + "Error_when_when_parsing_returned_value_style_fails": { prompt: "Hello!", convStyle: pam.PromptEchoOn, want: "Hey, hey!", @@ -675,7 +675,7 @@ func TestExecModule(t *testing.T) { }, wantExitError: pam_test.ErrInvalidArguments, }, - "Error when when parsing returned reply fails": { + "Error_when_when_parsing_returned_reply_fails": { prompt: "Hello!", convStyle: pam.PromptEchoOff, want: "Hey, hey!", @@ -763,18 +763,18 @@ func TestExecModule(t *testing.T) { want string wantError error }{ - "Getting a previously set user does not require conversation handler": { + "Getting_a_previously_set_user_does_not_require_conversation_handler": { presetUser: "an-user", want: "an-user", }, - "Getting a previously set user does not use conversation handler": { + "Getting_a_previously_set_user_does_not_use_conversation_handler": { presetUser: "an-user", want: "an-user", convHandler: pam.ConversationFunc(func(s pam.Style, msg string) (string, error) { return "another-user", pam.ErrConv }), }, - "Getting the user uses conversation handler if none was set": { + "Getting_the_user_uses_conversation_handler_if_none_was_set": { want: "provided-user", convHandler: pam.ConversationFunc( func(s pam.Style, msg string) (string, error) { @@ -790,7 +790,7 @@ func TestExecModule(t *testing.T) { }, // Error cases - "Error when no conversation is set": { + "Error_when_no_conversation_is_set": { want: "", wantError: pam.ErrConv, }, diff --git a/pam/integration-tests/gdm_test.go b/pam/integration-tests/gdm_test.go index 38104d631..e4d8bf75c 100644 --- a/pam/integration-tests/gdm_test.go +++ b/pam/integration-tests/gdm_test.go @@ -144,7 +144,7 @@ func TestGdmModule(t *testing.T) { wantPamErrorMessages []string wantAcctMgmtErr error }{ - "Authenticates user": { + "Authenticates_user": { eventPollResponses: map[gdm.EventType][]*gdm.EventData{ gdm.EventType_startAuthentication: { gdm_test.IsAuthenticatedEvent(&authd.IARequest_AuthenticationData_Challenge{ @@ -153,7 +153,7 @@ func TestGdmModule(t *testing.T) { }, }, }, - "Authenticates user with invalid connection timeout": { + "Authenticates_user_with_invalid_connection_timeout": { moduleArgs: []string{"connection_timeout=invalid"}, eventPollResponses: map[gdm.EventType][]*gdm.EventData{ gdm.EventType_startAuthentication: { @@ -163,7 +163,7 @@ func TestGdmModule(t *testing.T) { }, }, }, - "Authenticates user with multiple retries": { + "Authenticates_user_with_multiple_retries": { wantAuthModeIDs: []string{passwordAuthID, passwordAuthID, passwordAuthID}, eventPollResponses: map[gdm.EventType][]*gdm.EventData{ gdm.EventType_startAuthentication: { @@ -190,7 +190,7 @@ func TestGdmModule(t *testing.T) { {Access: auth.Granted}, }, }, - "Authenticates with MFA": { + "Authenticates_with_MFA": { pamUser: ptrValue("user-mfa-integration-basic"), wantAuthModeIDs: []string{passwordAuthID, fido1AuthID, phoneAck1ID}, eventPollResponses: map[gdm.EventType][]*gdm.EventData{ @@ -217,7 +217,7 @@ func TestGdmModule(t *testing.T) { {Access: auth.Granted}, }, }, - "Authenticates user with MFA after retry": { + "Authenticates_user_with_MFA_after_retry": { pamUser: ptrValue("user-mfa-integration-retry"), wantAuthModeIDs: []string{passwordAuthID, passwordAuthID, fido1AuthID, phoneAck1ID}, eventPollResponses: map[gdm.EventType][]*gdm.EventData{ @@ -252,7 +252,7 @@ func TestGdmModule(t *testing.T) { {Access: auth.Granted}, }, }, - "Authenticates user switching to phone ack": { + "Authenticates_user_switching_to_phone_ack": { wantAuthModeIDs: []string{passwordAuthID, phoneAck1ID}, eventPollResponses: map[gdm.EventType][]*gdm.EventData{ gdm.EventType_startAuthentication: { @@ -275,7 +275,7 @@ func TestGdmModule(t *testing.T) { {Access: auth.Granted}, }, }, - "Authenticates after password change": { + "Authenticates_after_password_change": { pamUser: ptrValue("user-needs-reset-integration-gdm-pass"), wantAuthModeIDs: []string{passwordAuthID, newPasswordAuthID}, supportedLayouts: []*authd.UILayout{ @@ -298,7 +298,7 @@ func TestGdmModule(t *testing.T) { {Access: auth.Granted}, }, }, - "Authenticates after mfa authentication with wait and password change checking quality": { + "Authenticates_after_mfa_authentication_with_wait_and_password_change_checking_quality": { pamUser: ptrValue("user-mfa-needs-reset-integration-gdm-wait-and-new-password"), wantAuthModeIDs: []string{ passwordAuthID, @@ -366,7 +366,7 @@ func TestGdmModule(t *testing.T) { {Access: auth.Granted}, }, }, - "Authenticates after various invalid password changes": { + "Authenticates_after_various_invalid_password_changes": { pamUser: ptrValue("user-needs-reset-integration-gdm-retries"), wantAuthModeIDs: []string{ passwordAuthID, @@ -428,7 +428,7 @@ func TestGdmModule(t *testing.T) { }, }, }, - "Authenticates user with qrcode": { + "Authenticates_user_with_qrcode": { wantAuthModeIDs: []string{qrcodeID}, supportedLayouts: []*authd.UILayout{pam_test.QrCodeUILayout()}, eventPollResponses: map[gdm.EventType][]*gdm.EventData{ @@ -440,7 +440,7 @@ func TestGdmModule(t *testing.T) { }, wantUILayouts: []*authd.UILayout{&testQrcodeUILayout}, }, - "Authenticates user with qrcode without code field": { + "Authenticates_user_with_qrcode_without_code_field": { wantAuthModeIDs: []string{qrcodeWithoutCodeID}, supportedLayouts: []*authd.UILayout{ pam_test.QrCodeUILayout(pam_test.WithQrCodeCode("")), @@ -454,7 +454,7 @@ func TestGdmModule(t *testing.T) { }, wantUILayouts: []*authd.UILayout{&testQrcodeUIWithoutCodeLayout}, }, - "Authenticates user with qrcode without rendering support": { + "Authenticates_user_with_qrcode_without_rendering_support": { wantAuthModeIDs: []string{qrcodeWithoutRenderingID}, supportedLayouts: []*authd.UILayout{ pam_test.QrCodeUILayout(pam_test.WithQrCodeRenders(ptrValue(false))), @@ -468,7 +468,7 @@ func TestGdmModule(t *testing.T) { }, wantUILayouts: []*authd.UILayout{&testQrcodeUIWithoutRendering}, }, - "Authenticates user with qrcode without explicit rendering support": { + "Authenticates_user_with_qrcode_without_explicit_rendering_support": { // This checks that we're backward compatible wantAuthModeIDs: []string{qrcodeID}, supportedLayouts: []*authd.UILayout{ @@ -483,7 +483,7 @@ func TestGdmModule(t *testing.T) { }, wantUILayouts: []*authd.UILayout{&testQrcodeUILayout}, }, - "Authenticates user after switching to qrcode": { + "Authenticates_user_after_switching_to_qrcode": { wantAuthModeIDs: []string{passwordAuthID, qrcodeID}, supportedLayouts: []*authd.UILayout{ pam_test.FormUILayout(), @@ -510,7 +510,7 @@ func TestGdmModule(t *testing.T) { {Access: auth.Granted}, }, }, - "Authenticates user after regenerating the qrcode with optional code field": { + "Authenticates_user_after_regenerating_the_qrcode_with_optional_code_field": { wantAuthModeIDs: []string{ passwordAuthID, qrcodeID, @@ -575,7 +575,7 @@ func TestGdmModule(t *testing.T) { {Access: auth.Granted}, }, }, - "Authenticates user after regenerating the qrcode without code field": { + "Authenticates_user_after_regenerating_the_qrcode_without_code_field": { wantAuthModeIDs: []string{ passwordAuthID, qrcodeWithoutCodeID, @@ -642,7 +642,7 @@ func TestGdmModule(t *testing.T) { }, // Error cases - "Error on unknown protocol": { + "Error_on_unknown_protocol": { protoVersion: 9999, wantPamErrorMessages: []string{ "GDM protocol initialization failed, type hello, version 9999", @@ -650,7 +650,7 @@ func TestGdmModule(t *testing.T) { wantError: pam.ErrCredUnavail, wantAcctMgmtErr: pam_test.ErrIgnore, }, - "Error on connection failure": { + "Error_on_connection_failure": { moduleArgs: []string{fmt.Sprintf("socket=%s_invalid", socketPath)}, wantPamErrorMessages: []string{ fmt.Sprintf("could not connect to unix://%s_invalid: service took too long to respond. Disconnecting client", socketPath), @@ -658,7 +658,7 @@ func TestGdmModule(t *testing.T) { wantError: pam.ErrAuthinfoUnavail, wantAcctMgmtErr: pam_test.ErrIgnore, }, - "Error on missing user": { + "Error_on_missing_user": { pamUser: ptrValue(""), eventPollResponses: map[gdm.EventType][]*gdm.EventData{ gdm.EventType_brokersReceived: { @@ -671,7 +671,7 @@ func TestGdmModule(t *testing.T) { wantError: pam.ErrSystem, wantAcctMgmtErr: pam_test.ErrIgnore, }, - "Error on no supported layouts": { + "Error_on_no_supported_layouts": { supportedLayouts: []*authd.UILayout{}, wantPamErrorMessages: []string{ "UI does not support any layouts", @@ -679,7 +679,7 @@ func TestGdmModule(t *testing.T) { wantError: pam.ErrCredUnavail, wantAcctMgmtErr: pam_test.ErrIgnore, }, - "Error on unknown broker": { + "Error_on_unknown_broker": { brokerName: "Not a valid broker!", wantPamErrorMessages: []string{ "Changing GDM stage failed: Conversation error", @@ -687,7 +687,7 @@ func TestGdmModule(t *testing.T) { wantError: pam.ErrSystem, wantAcctMgmtErr: pam_test.ErrIgnore, }, - "Error (ignored) on local broker causes fallback error": { + "Error_(ignored)_on_local_broker_causes_fallback_error": { brokerName: brokers.LocalBrokerName, wantPamInfoMessages: []string{ "auth=incomplete", @@ -695,7 +695,7 @@ func TestGdmModule(t *testing.T) { wantError: pam_test.ErrIgnore, wantAcctMgmtErr: pam.ErrAbort, }, - "Error on authenticating user with too many retries": { + "Error_on_authenticating_user_with_too_many_retries": { wantAuthModeIDs: []string{ passwordAuthID, passwordAuthID, @@ -754,7 +754,7 @@ func TestGdmModule(t *testing.T) { wantError: pam.ErrAuth, wantAcctMgmtErr: pam_test.ErrIgnore, }, - "Error on authenticating unknown user": { + "Error_on_authenticating_unknown_user": { pamUser: ptrValue("user-unknown"), eventPollResponses: map[gdm.EventType][]*gdm.EventData{ gdm.EventType_startAuthentication: { @@ -775,7 +775,7 @@ func TestGdmModule(t *testing.T) { wantError: pam.ErrAuth, wantAcctMgmtErr: pam_test.ErrIgnore, }, - "Error on invalid fido ack": { + "Error_on_invalid_fido_ack": { pamUser: ptrValue("user-mfa-integration-error-fido-ack"), wantAuthModeIDs: []string{passwordAuthID, fido1AuthID}, eventPollResponses: map[gdm.EventType][]*gdm.EventData{ diff --git a/pam/integration-tests/native_test.go b/pam/integration-tests/native_test.go index f373c1b6e..cf5214789 100644 --- a/pam/integration-tests/native_test.go +++ b/pam/integration-tests/native_test.go @@ -40,31 +40,31 @@ func TestNativeAuthenticate(t *testing.T) { skipRunnerCheck bool socketPath string }{ - "Authenticate user successfully": { + "Authenticate_user_successfully": { tape: "simple_auth", clientOptions: clientOptions{PamUser: "user-integration-simple-auth"}, }, - "Authenticate user successfully with user selection": { + "Authenticate_user_successfully_with_user_selection": { tape: "simple_auth_with_user_selection", }, - "Authenticate user successfully with invalid connection timeout": { + "Authenticate_user_successfully_with_invalid_connection_timeout": { tape: "simple_auth", clientOptions: clientOptions{ PamUser: "user-integration-simple-auth-invalid-timeout", PamTimeout: "invalid", }, }, - "Authenticate user with mfa": { + "Authenticate_user_with_mfa": { tape: "mfa_auth", tapeSettings: []tapeSetting{{vhsHeight, 1200}}, clientOptions: clientOptions{PamUser: "user-mfa-integration-auth"}, }, - "Authenticate user with form mode with button": { + "Authenticate_user_with_form_mode_with_button": { tape: "form_with_button", tapeSettings: []tapeSetting{{vhsHeight, 700}}, clientOptions: clientOptions{PamUser: "user-integration-form-w-button"}, }, - "Authenticate user with qr code": { + "Authenticate_user_with_qr_code": { tape: "qr_code", tapeSettings: []tapeSetting{{vhsHeight, 3000}}, tapeVariables: map[string]string{ @@ -73,7 +73,7 @@ func TestNativeAuthenticate(t *testing.T) { }, clientOptions: clientOptions{PamUser: "user-integration-qr-code"}, }, - "Authenticate user with qr code in a TTY": { + "Authenticate_user_with_qr_code_in_a_TTY": { tape: "qr_code", tapeSettings: []tapeSetting{{vhsHeight, 4000}}, tapeVariables: map[string]string{ @@ -85,7 +85,7 @@ func TestNativeAuthenticate(t *testing.T) { Term: "linux", }, }, - "Authenticate user with qr code in a TTY session": { + "Authenticate_user_with_qr_code_in_a_TTY_session": { tape: "qr_code", tapeSettings: []tapeSetting{{vhsHeight, 4000}}, tapeVariables: map[string]string{ @@ -97,7 +97,7 @@ func TestNativeAuthenticate(t *testing.T) { Term: "xterm-256color", SessionType: "tty", }, }, - "Authenticate user with qr code in screen": { + "Authenticate_user_with_qr_code_in_screen": { tape: "qr_code", tapeSettings: []tapeSetting{{vhsHeight, 4000}}, tapeVariables: map[string]string{ @@ -109,7 +109,7 @@ func TestNativeAuthenticate(t *testing.T) { Term: "screen", }, }, - "Authenticate user with qr code in polkit": { + "Authenticate_user_with_qr_code_in_polkit": { tape: "qr_code", tapeSettings: []tapeSetting{{vhsHeight, 3500}}, tapeVariables: map[string]string{ @@ -121,7 +121,7 @@ func TestNativeAuthenticate(t *testing.T) { PamServiceName: "polkit-1", }, }, - "Authenticate user with qr code in ssh": { + "Authenticate_user_with_qr_code_in_ssh": { tape: "qr_code", tapeSettings: []tapeSetting{{vhsHeight, 3500}}, tapeVariables: map[string]string{ @@ -133,24 +133,24 @@ func TestNativeAuthenticate(t *testing.T) { PamServiceName: "sshd", }, }, - "Authenticate user and reset password while enforcing policy": { + "Authenticate_user_and_reset_password_while_enforcing_policy": { tape: "mandatory_password_reset", clientOptions: clientOptions{PamUser: "user-needs-reset-integration-mandatory"}, }, - "Authenticate user with mfa and reset password while enforcing policy": { + "Authenticate_user_with_mfa_and_reset_password_while_enforcing_policy": { tape: "mfa_reset_pwquality_auth", tapeSettings: []tapeSetting{{vhsHeight, 3000}}, clientOptions: clientOptions{PamUser: "user-mfa-with-reset-integration-pwquality"}, }, - "Authenticate user and offer password reset": { + "Authenticate_user_and_offer_password_reset": { tape: "optional_password_reset_skip", clientOptions: clientOptions{PamUser: "user-can-reset-integration-skip"}, }, - "Authenticate user and accept password reset": { + "Authenticate_user_and_accept_password_reset": { tape: "optional_password_reset_accept", clientOptions: clientOptions{PamUser: "user-can-reset-integration-accept"}, }, - "Authenticate user switching auth mode": { + "Authenticate_user_switching_auth_mode": { tape: "switch_auth_mode", tapeSettings: []tapeSetting{{vhsHeight, 3000}}, clientOptions: clientOptions{PamUser: "user-integration-switch-mode"}, @@ -166,109 +166,109 @@ func TestNativeAuthenticate(t *testing.T) { "AUTHD_SWITCH_AUTH_MODE_TAPE_QR_OR_LOGIN_CODE_ITEM_NAME": "QR code", }, }, - "Authenticate user switching username": { + "Authenticate_user_switching_username": { tape: "switch_username", }, - "Authenticate user switching to local broker": { + "Authenticate_user_switching_to_local_broker": { tape: "switch_local_broker", tapeSettings: []tapeSetting{{vhsHeight, 700}}, clientOptions: clientOptions{PamUser: "user-integration-switch-broker"}, }, - "Authenticate user and add it to local group": { + "Authenticate_user_and_add_it_to_local_group": { tape: "local_group", tapeSettings: []tapeSetting{{vhsHeight, 700}}, wantLocalGroups: true, clientOptions: clientOptions{PamUser: "user-local-groups"}, }, - "Authenticate user on ssh service": { + "Authenticate_user_on_ssh_service": { tape: "simple_ssh_auth", clientOptions: clientOptions{ PamUser: "user-integration-pre-check-ssh-service", PamServiceName: "sshd", }, }, - "Authenticate user on ssh service with custom name and connection env": { + "Authenticate_user_on_ssh_service_with_custom_name_and_connection_env": { tape: "simple_ssh_auth", clientOptions: clientOptions{ PamUser: "user-integration-pre-check-ssh-connection", PamEnv: []string{"SSH_CONNECTION=foo-connection"}, }, }, - "Authenticate user on ssh service with custom name and auth info env": { + "Authenticate_user_on_ssh_service_with_custom_name_and_auth_info_env": { tape: "simple_ssh_auth", clientOptions: clientOptions{ PamUser: "user-integration-pre-check-ssh-auth-info", PamEnv: []string{"SSH_AUTH_INFO_0=foo-authinfo"}, }, }, - "Authenticate with warnings on unsupported arguments": { + "Authenticate_with_warnings_on_unsupported_arguments": { tape: "simple_auth_with_unsupported_args", tapeCommand: strings.ReplaceAll(tapeCommand, "force_native_client=true", "invalid_flag=foo force_native_client=true bar"), clientOptions: clientOptions{PamUser: "user-integration-with-unsupported-args"}, }, - "Remember last successful broker and mode": { + "Remember_last_successful_broker_and_mode": { tape: "remember_broker_and_mode", tapeSettings: []tapeSetting{{vhsHeight, 800}}, clientOptions: clientOptions{PamUser: "user-integration-remember-mode"}, }, - "Autoselect local broker for local user": { + "Autoselect_local_broker_for_local_user": { tape: "local_user", }, - "Autoselect local broker for local user preset": { + "Autoselect_local_broker_for_local_user_preset": { tape: "local_user_preset", clientOptions: clientOptions{PamUser: "root"}, }, - "Deny authentication if current user is not considered as root": { + "Deny_authentication_if_current_user_is_not_considered_as_root": { tape: "not_root", currentUserNotRoot: true, clientOptions: clientOptions{PamUser: "user-integration-not-root"}, }, - "Deny authentication if max attempts reached": { + "Deny_authentication_if_max_attempts_reached": { tape: "max_attempts", tapeSettings: []tapeSetting{{vhsHeight, 700}}, clientOptions: clientOptions{PamUser: "user-integration-max-attempts"}, }, - "Deny authentication if user does not exist": { + "Deny_authentication_if_user_does_not_exist": { tape: "unexistent_user", clientOptions: clientOptions{PamUser: "user-unexistent"}, }, - "Deny authentication if user does not exist and matches cancel key": { + "Deny_authentication_if_user_does_not_exist_and_matches_cancel_key": { tape: "cancel_key_user", }, - "Deny authentication if newpassword does not match required criteria": { + "Deny_authentication_if_newpassword_does_not_match_required_criteria": { tape: "bad_password", tapeSettings: []tapeSetting{{vhsHeight, 800}}, clientOptions: clientOptions{PamUser: "user-needs-reset-integration-bad-password"}, }, - "Prevent preset user from switching username": { + "Prevent_preset_user_from_switching_username": { tape: "switch_preset_username", tapeSettings: []tapeSetting{{vhsHeight, 800}}, clientOptions: clientOptions{PamUser: "user-integration-pam-preset"}, }, - "Exit authd if local broker is selected": { + "Exit_authd_if_local_broker_is_selected": { tape: "local_broker", clientOptions: clientOptions{PamUser: "user-local-broker"}, }, - "Exit if user is not pre-checked on ssh service": { + "Exit_if_user_is_not_pre-checked_on_ssh_service": { tape: "local_ssh", clientOptions: clientOptions{ PamUser: "user-integration-ssh-service", PamServiceName: "sshd", }, }, - "Exit if user is not pre-checked on custom ssh service with connection env": { + "Exit_if_user_is_not_pre-checked_on_custom_ssh_service_with_connection_env": { tape: "local_ssh", clientOptions: clientOptions{ PamUser: "user-integration-ssh-connection", PamEnv: []string{"SSH_CONNECTION=foo-connection"}, }, }, - "Exit if user is not pre-checked on custom ssh service with auth info env": { + "Exit_if_user_is_not_pre-checked_on_custom_ssh_service_with_auth_info_env": { tape: "local_ssh", clientOptions: clientOptions{ PamUser: "user-integration-ssh-auth-info", @@ -276,18 +276,18 @@ func TestNativeAuthenticate(t *testing.T) { }, }, // FIXME: While this works now, it requires proper handling via signal_fd - "Exit authd if user sigints": { + "Exit_authd_if_user_sigints": { tape: "sigint", clientOptions: clientOptions{PamUser: "user-integration-sigint"}, skipRunnerCheck: true, }, - "Exit if authd is stopped": { + "Exit_if_authd_is_stopped": { tape: "authd_stopped", clientOptions: clientOptions{PamUser: "user-integration-authd-stopped"}, stopDaemonAfter: sleepDuration(defaultSleepValues[authdSleepLong] * 5), }, - "Error if cannot connect to authd": { + "Error_if_cannot_connect_to_authd": { tape: "connection_error", socketPath: "/some-path/not-existent-socket", }, @@ -366,49 +366,49 @@ func TestNativeChangeAuthTok(t *testing.T) { currentUserNotRoot bool skipRunnerCheck bool }{ - "Change password successfully and authenticate with new one": { + "Change_password_successfully_and_authenticate_with_new_one": { tape: "passwd_simple", tapeVariables: map[string]string{ "AUTHD_TEST_TAPE_LOGIN_COMMAND": fmt.Sprintf( tapeBaseCommand, pam_test.RunnerActionLogin, socketPathEnv), }, }, - "Change passwd after MFA auth": { + "Change_passwd_after_MFA_auth": { tape: "passwd_mfa", tapeSettings: []tapeSetting{{vhsHeight, 1300}}, }, - "Retry if new password is rejected by broker": { + "Retry_if_new_password_is_rejected_by_broker": { tape: "passwd_rejected", tapeSettings: []tapeSetting{{vhsHeight, 1000}}, }, - "Retry if new password is same of previous": { + "Retry_if_new_password_is_same_of_previous": { tape: "passwd_not_changed", }, - "Retry if password confirmation is not the same": { + "Retry_if_password_confirmation_is_not_the_same": { tape: "passwd_not_confirmed", }, - "Retry if new password does not match quality criteria": { + "Retry_if_new_password_does_not_match_quality_criteria": { tape: "passwd_bad_password", tapeSettings: []tapeSetting{{vhsHeight, 800}}, }, - "Prevent change password if auth fails": { + "Prevent_change_password_if_auth_fails": { tape: "passwd_auth_fail", tapeSettings: []tapeSetting{{vhsHeight, 700}}, }, - "Prevent change password if user does not exist": { + "Prevent_change_password_if_user_does_not_exist": { tape: "passwd_unexistent_user", }, - "Prevent change password if current user is not root as can not authenticate": { + "Prevent_change_password_if_current_user_is_not_root_as_can_not_authenticate": { tape: "passwd_not_root", currentUserNotRoot: true, }, - "Exit authd if local broker is selected": { + "Exit_authd_if_local_broker_is_selected": { tape: "passwd_local_broker", }, // FIXME: While this works now, it requires proper handling via signal_fd - "Exit authd if user sigints": { + "Exit_authd_if_user_sigints": { tape: "passwd_sigint", skipRunnerCheck: true, }, diff --git a/pam/integration-tests/ssh_test.go b/pam/integration-tests/ssh_test.go index 7e299624f..20ce277a9 100644 --- a/pam/integration-tests/ssh_test.go +++ b/pam/integration-tests/ssh_test.go @@ -110,23 +110,23 @@ func testSSHAuthenticate(t *testing.T, sharedSSHd bool) { wantNotLoggedInUser bool wantLocalGroups bool }{ - "Authenticate user successfully": { + "Authenticate_user_successfully": { tape: "simple_auth", }, - "Authenticate user successfully and enters shell": { + "Authenticate_user_successfully_and_enters_shell": { tape: "simple_auth_with_shell", interactiveShell: true, }, - "Authenticate user with mfa": { + "Authenticate_user_with_mfa": { tape: "mfa_auth", tapeSettings: []tapeSetting{{vhsHeight, 1200}}, user: "user-mfa", }, - "Authenticate user with form mode with button": { + "Authenticate_user_with_form_mode_with_button": { tape: "form_with_button", tapeSettings: []tapeSetting{{vhsHeight, 1500}}, }, - "Authenticate user with qr code": { + "Authenticate_user_with_qr_code": { tape: "qr_code", tapeSettings: []tapeSetting{{vhsHeight, 1500}}, tapeVariables: map[string]string{ @@ -134,24 +134,24 @@ func testSSHAuthenticate(t *testing.T, sharedSSHd bool) { "AUTHD_QRCODE_TAPE_ITEM_NAME": "Login code", }, }, - "Authenticate user and reset password while enforcing policy": { + "Authenticate_user_and_reset_password_while_enforcing_policy": { tape: "mandatory_password_reset", user: "user-needs-reset", }, - "Authenticate user with mfa and reset password while enforcing policy": { + "Authenticate_user_with_mfa_and_reset_password_while_enforcing_policy": { tape: "mfa_reset_pwquality_auth", user: "user-mfa-with-reset", tapeSettings: []tapeSetting{{vhsHeight, 1500}}, }, - "Authenticate user and offer password reset": { + "Authenticate_user_and_offer_password_reset": { tape: "optional_password_reset_skip", user: "user-can-reset", }, - "Authenticate user and accept password reset": { + "Authenticate_user_and_accept_password_reset": { tape: "optional_password_reset_accept", user: "user-can-reset2", }, - "Authenticate user switching auth mode": { + "Authenticate_user_switching_auth_mode": { tape: "switch_auth_mode", tapeSettings: []tapeSetting{{vhsHeight, 3500}}, tapeVariables: map[string]string{ @@ -166,7 +166,7 @@ func testSSHAuthenticate(t *testing.T, sharedSSHd bool) { "AUTHD_SWITCH_AUTH_MODE_TAPE_QR_OR_LOGIN_CODE_ITEM_NAME": "Login code", }, }, - "Authenticate user switching to local broker": { + "Authenticate_user_switching_to_local_broker": { tape: "switch_local_broker", wantNotLoggedInUser: true, tapeSettings: []tapeSetting{{vhsHeight, 900}}, @@ -174,17 +174,17 @@ func testSSHAuthenticate(t *testing.T, sharedSSHd bool) { vhsCommandFinalAuthWaitVariable: `Wait /Password:/`, }, }, - "Authenticate user and add it to local group": { + "Authenticate_user_and_add_it_to_local_group": { tape: "local_group", user: "user-local-groups", wantLocalGroups: true, }, - "Remember last successful broker and mode": { + "Remember_last_successful_broker_and_mode": { tape: "remember_broker_and_mode", daemonizeSSHd: true, }, - "Autoselect local broker for local user": { + "Autoselect_local_broker_for_local_user": { tape: "local_user_preset", user: "root", wantNotLoggedInUser: true, @@ -196,7 +196,7 @@ func testSSHAuthenticate(t *testing.T, sharedSSHd bool) { }, }, - "Deny authentication if max attempts reached": { + "Deny_authentication_if_max_attempts_reached": { tape: "max_attempts", wantNotLoggedInUser: true, tapeVariables: map[string]string{ @@ -204,33 +204,33 @@ func testSSHAuthenticate(t *testing.T, sharedSSHd bool) { Wait`, }, }, - "Deny authentication if user does not exist": { + "Deny_authentication_if_user_does_not_exist": { tape: "unexistent_user", user: "user-unexistent", wantNotLoggedInUser: true, }, - "Deny authentication if user does not exist and matches cancel key": { + "Deny_authentication_if_user_does_not_exist_and_matches_cancel_key": { tape: "cancel_key_user", user: "r", wantNotLoggedInUser: true, }, - "Deny authentication if newpassword does not match required criteria": { + "Deny_authentication_if_newpassword_does_not_match_required_criteria": { tape: "bad_password", user: "user-needs-reset2", }, - "Prevent user from switching username": { + "Prevent_user_from_switching_username": { tape: "switch_preset_username", }, - "Exit authd if local broker is selected": { + "Exit_authd_if_local_broker_is_selected": { tape: "local_broker", wantNotLoggedInUser: true, tapeVariables: map[string]string{ vhsCommandFinalAuthWaitVariable: `Wait /Password:/`, }, }, - "Exit if user is not pre-checked on ssh service": { + "Exit_if_user_is_not_pre-checked_on_ssh_service": { tape: "local_ssh", user: "user-integration-ssh-service-not-allowed", pamServiceName: "sshd", @@ -239,12 +239,12 @@ Wait`, vhsCommandFinalAuthWaitVariable: `Wait /Password:/`, }, }, - "Exit authd if user sigints": { + "Exit_authd_if_user_sigints": { tape: "sigint", wantNotLoggedInUser: true, }, - "Error if cannot connect to authd": { + "Error_if_cannot_connect_to_authd": { tape: "connection_error", socketPath: "/some-path/not-existent-socket", wantNotLoggedInUser: true, diff --git a/pam/internal/adapter/gdmmodel_test.go b/pam/internal/adapter/gdmmodel_test.go index 9f1647095..48f225191 100644 --- a/pam/internal/adapter/gdmmodel_test.go +++ b/pam/internal/adapter/gdmmodel_test.go @@ -101,7 +101,7 @@ func TestGdmModel(t *testing.T) { wantUsername string wantMessages []tea.Msg }{ - "User selection stage": { + "User_selection_stage": { wantGdmRequests: []gdm.RequestType{gdm.RequestType_uiLayoutCapabilities}, wantStage: pam_proto.Stage_userSelection, wantGdmEvents: []gdm.EventType{ @@ -119,7 +119,7 @@ func TestGdmModel(t *testing.T) { }, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "Broker selection stage caused by PAM user selection": { + "Broker_selection_stage_caused_by_PAM_user_selection": { pamUser: "pam-preset-user", wantGdmRequests: []gdm.RequestType{ gdm.RequestType_uiLayoutCapabilities, @@ -139,7 +139,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_brokerSelection, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "Broker selection stage caused by client-side user selection": { + "Broker_selection_stage_caused_by_client-side_user_selection": { gdmEvents: []*gdm.EventData{ gdm_test.SelectUserEvent("gdm-selected-user"), }, @@ -162,7 +162,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_brokerSelection, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "Challenge stage caused by server-side broker and authMode selection": { + "Challenge_stage_caused_by_server-side_broker_and_authMode_selection": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil)), pamUser: "pam-preset-user-and-daemon-selected-broker", @@ -190,7 +190,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_challenge, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "Challenge stage caused by client-side broker and authMode selection": { + "Challenge_stage_caused_by_client-side_broker_and_authMode_selection": { gdmEvents: []*gdm.EventData{ gdm_test.SelectUserEvent("gdm-selected-user-and-broker"), }, @@ -226,7 +226,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_challenge, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "Authenticated with preset PAM user and server-side broker and authMode selection": { + "Authenticated_with_preset_PAM_user_and_server-side_broker_and_authMode_selection": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithIsAuthenticatedWantChallenge("gdm-good-password")), @@ -261,7 +261,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_challenge, wantExitStatus: PamSuccess{BrokerID: firstBrokerInfo.Id}, }, - "Authenticated with message with preset PAM user and server-side broker and authMode selection": { + "Authenticated_with_message_with_preset_PAM_user_and_server-side_broker_and_authMode_selection": { clientOptions: append(slices.Clone(multiBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithIsAuthenticatedReturn(&authd.IAResponse{ @@ -306,7 +306,7 @@ func TestGdmModel(t *testing.T) { msg: "Hi GDM, it's a pleasure to get you in!", }, }, - "New password changed after server-side broker and authMode selection": { + "New_password_changed_after_server-side_broker_and_authMode_selection": { clientOptions: append(slices.Clone(singleBrokerNewPasswordClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithIsAuthenticatedReturn(&authd.IAResponse{ @@ -349,7 +349,7 @@ func TestGdmModel(t *testing.T) { BrokerID: firstBrokerInfo.Id, }, }, - "New password changed with message with preset PAM user and server-side broker and authMode selection": { + "New_password_changed_with_message_with_preset_PAM_user_and_server-side_broker_and_authMode_selection": { clientOptions: append(slices.Clone(singleBrokerNewPasswordClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithIsAuthenticatedReturn(&authd.IAResponse{ @@ -395,7 +395,7 @@ func TestGdmModel(t *testing.T) { msg: "Hi GDM, it's a pleasure to change your password!", }, }, - "New password can't change because not respecting rules with preset PAM user and server-side broker and authMode selection": { + "New_password_can't_change_because_not_respecting_rules_with_preset_PAM_user_and_server-side_broker_and_authMode_selection": { clientOptions: append(slices.Clone(singleBrokerNewPasswordClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithIsAuthenticatedReturn(&authd.IAResponse{ @@ -461,7 +461,7 @@ func TestGdmModel(t *testing.T) { msg: "Hi GDM, it's a pleasure to change your password!", }, }, - "New password can't change because matches previous with preset PAM user and server-side broker and authMode selection": { + "New_password_can't_change_because_matches_previous_with_preset_PAM_user_and_server-side_broker_and_authMode_selection": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithUILayout(newPasswordUILayoutID, "New Password", pam_test.NewPasswordUILayout()), @@ -548,7 +548,7 @@ func TestGdmModel(t *testing.T) { }, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "Authentication is ignored if not requested by model first": { + "Authentication_is_ignored_if_not_requested_by_model_first": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithIsAuthenticatedWantChallenge("gdm-good-password")), gdmEvents: []*gdm.EventData{ @@ -576,7 +576,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_userSelection, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "Cancelled with preset PAM user and server-side broker and authMode selection": { + "Cancelled_with_preset_PAM_user_and_server-side_broker_and_authMode_selection": { clientOptions: append(slices.Clone(multiBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithIsAuthenticatedReturn(&authd.IAResponse{ @@ -609,7 +609,7 @@ func TestGdmModel(t *testing.T) { wantGdmAuthRes: []*authd.IAResponse{{Access: auth.Cancelled}}, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "Explicitly cancelled with preset PAM user and server-side broker and authMode selection": { + "Explicitly_cancelled_with_preset_PAM_user_and_server-side_broker_and_authMode_selection": { clientOptions: append(slices.Clone(multiBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), ), @@ -642,7 +642,7 @@ func TestGdmModel(t *testing.T) { wantGdmAuthRes: []*authd.IAResponse{{Access: auth.Cancelled}}, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "Authenticated with preset PAM user and server-side broker and authMode selection and after various retries": { + "Authenticated_with_preset_PAM_user_and_server-side_broker_and_authMode_selection_and_after_various_retries": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithIsAuthenticatedWantChallenge("gdm-good-password"), @@ -691,7 +691,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_challenge, wantExitStatus: PamSuccess{BrokerID: firstBrokerInfo.Id}, }, - "Authenticated after client-side user and broker and authMode selection": { + "Authenticated_after_client-side_user_and_broker_and_authMode_selection": { clientOptions: append(slices.Clone(multiBrokerClientOptions), pam_test.WithIsAuthenticatedWantChallenge("gdm-good-password"), ), @@ -732,7 +732,7 @@ func TestGdmModel(t *testing.T) { wantGdmAuthRes: []*authd.IAResponse{{Access: auth.Granted}}, wantExitStatus: PamSuccess{BrokerID: secondBrokerInfo.Id}, }, - "Authenticated after client-side user and broker and authMode selection and after various retries": { + "Authenticated_after_client-side_user_and_broker_and_authMode_selection_and_after_various_retries": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithIsAuthenticatedWantChallenge("gdm-good-password"), pam_test.WithIsAuthenticatedMaxRetries(1), @@ -789,7 +789,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_challenge, wantExitStatus: PamSuccess{BrokerID: firstBrokerInfo.Id}, }, - "Cancelled auth after client-side user and broker and authMode selection": { + "Cancelled_auth_after_client-side_user_and_broker_and_authMode_selection": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithIsAuthenticatedReturn(&authd.IAResponse{ Access: auth.Cancelled, @@ -833,7 +833,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_challenge, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "AuthMode selection stage from client after server-side broker and auth mode selection if there is only one auth mode": { + "AuthMode_selection_stage_from_client_after_server-side_broker_and_auth_mode_selection_if_there_is_only_one_auth_mode": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), ), @@ -874,7 +874,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_authModeSelection, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "AuthMode selection stage from client after server-side broker and auth mode selection with multiple auth modes": { + "AuthMode_selection_stage_from_client_after_server-side_broker_and_auth_mode_selection_with_multiple_auth_modes": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithUILayout("pincode", "Pin Code", pam_test.FormUILayout()), @@ -913,7 +913,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_authModeSelection, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "AuthMode selection stage from client after client-side broker and auth mode selection if there is only one auth mode": { + "AuthMode_selection_stage_from_client_after_client-side_broker_and_auth_mode_selection_if_there_is_only_one_auth_mode": { gdmEvents: []*gdm.EventData{ gdm_test.SelectUserEvent("gdm-selected-user-broker-and-auth-mode"), }, @@ -960,7 +960,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_authModeSelection, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "Authenticated after auth selection stage from client after client-side broker and auth mode selection if there is only one auth mode": { + "Authenticated_after_auth_selection_stage_from_client_after_client-side_broker_and_auth_mode_selection_if_there_is_only_one_auth_mode": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithIsAuthenticatedWantChallenge("gdm-good-password"), ), @@ -1027,7 +1027,7 @@ func TestGdmModel(t *testing.T) { }, wantExitStatus: PamSuccess{BrokerID: firstBrokerInfo.Id}, }, - "Authenticated after auth selection stage from client after client-side broker and auth mode selection with multiple auth modes": { + "Authenticated_after_auth_selection_stage_from_client_after_client-side_broker_and_auth_mode_selection_with_multiple_auth_modes": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithUILayout("pincode", "Write the pin Code", pam_test.FormUILayout()), pam_test.WithIsAuthenticatedWantChallenge("1234"), @@ -1096,7 +1096,7 @@ func TestGdmModel(t *testing.T) { }, wantExitStatus: PamSuccess{BrokerID: firstBrokerInfo.Id}, }, - "Authenticated with qrcode after auth selection stage from client after client-side broker and auth mode selection": { + "Authenticated_with_qrcode_after_auth_selection_stage_from_client_after_client-side_broker_and_auth_mode_selection": { supportedLayouts: []*authd.UILayout{ pam_test.FormUILayout(), pam_test.QrCodeUILayout(), @@ -1169,7 +1169,7 @@ func TestGdmModel(t *testing.T) { }, wantExitStatus: PamSuccess{BrokerID: firstBrokerInfo.Id}, }, - "Authenticated with qrcode regenerated after auth selection stage from client after client-side broker and auth mode selection": { + "Authenticated_with_qrcode_regenerated_after_auth_selection_stage_from_client_after_client-side_broker_and_auth_mode_selection": { timeout: 10 * time.Second, supportedLayouts: []*authd.UILayout{ pam_test.FormUILayout(), @@ -1251,7 +1251,7 @@ func TestGdmModel(t *testing.T) { }, wantExitStatus: PamSuccess{BrokerID: firstBrokerInfo.Id}, }, - "Authenticated with qrcode regenerated after wait started at auth selection stage from client after client-side broker and auth mode selection": { + "Authenticated_with_qrcode_regenerated_after_wait_started_at_auth_selection_stage_from_client_after_client-side_broker_and_auth_mode_selection": { timeout: 10 * time.Second, supportedLayouts: []*authd.UILayout{ pam_test.FormUILayout(), @@ -1338,7 +1338,7 @@ func TestGdmModel(t *testing.T) { }, wantExitStatus: PamSuccess{BrokerID: firstBrokerInfo.Id}, }, - "Broker selection stage from client after client-side broker and auth mode selection if there is only one auth mode": { + "Broker_selection_stage_from_client_after_client-side_broker_and_auth_mode_selection_if_there_is_only_one_auth_mode": { gdmEvents: []*gdm.EventData{ gdm_test.SelectUserEvent("gdm-selected-user-broker-and-auth-mode"), }, @@ -1390,7 +1390,7 @@ func TestGdmModel(t *testing.T) { wantStage: pam_proto.Stage_brokerSelection, wantExitStatus: gdmTestEarlyStopExitStatus, }, - "User selection stage from client after client-side broker and auth mode selection if there is only one auth mode": { + "User_selection_stage_from_client_after_client-side_broker_and_auth_mode_selection_if_there_is_only_one_auth_mode": { gdmEvents: []*gdm.EventData{ gdm_test.SelectUserEvent("gdm-selected-user-broker-and-auth-mode"), }, @@ -1456,7 +1456,7 @@ func TestGdmModel(t *testing.T) { }, // Error cases - "Error on no UI layouts": { + "Error_on_no_UI_layouts": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithUILayout(passwordUILayoutID, "", &authd.UILayout{}), ), @@ -1471,7 +1471,7 @@ func TestGdmModel(t *testing.T) { msg: "UI does not support any layouts", }, }, - "Error on brokers fetching error": { + "Error_on_brokers_fetching_error": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithAvailableBrokers(nil, errors.New("brokers loading failed")), ), @@ -1488,14 +1488,14 @@ func TestGdmModel(t *testing.T) { }, wantNoBrokers: true, }, - "Error on forced quit": { + "Error_on_forced_quit": { messages: []tea.Msg{tea.Quit()}, wantExitStatus: gdmTestEarlyStopExitStatus, wantNoGdmEvents: []gdm.EventType{ gdm.EventType_userSelected, }, }, - "Error on invalid poll data response for missing type": { + "Error_on_invalid_poll_data_response_for_missing_type": { wantGdmRequests: []gdm.RequestType{ gdm.RequestType_uiLayoutCapabilities, }, @@ -1515,7 +1515,7 @@ func TestGdmModel(t *testing.T) { msg: "Sending GDM poll failed: Conversation error: poll response data member 0 invalid: missing event data", }, }, - "Error on invalid poll data response for missing data": { + "Error_on_invalid_poll_data_response_for_missing_data": { wantGdmRequests: []gdm.RequestType{ gdm.RequestType_uiLayoutCapabilities, }, @@ -1531,7 +1531,7 @@ func TestGdmModel(t *testing.T) { msg: "Sending GDM poll failed: Conversation error: poll response data member 0 invalid: missing event type", }, }, - "Error on no brokers": { + "Error_on_no_brokers": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithAvailableBrokers(nil, nil), ), @@ -1547,7 +1547,7 @@ func TestGdmModel(t *testing.T) { msg: "No brokers available", }, }, - "Error on invalid broker selection": { + "Error_on_invalid_broker_selection": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithSelectBrokerReturn(nil, errors.New("error during broker selection")), @@ -1566,7 +1566,7 @@ func TestGdmModel(t *testing.T) { msg: "can't select broker: error during broker selection", }, }, - "Error during broker selection if session ID is empty": { + "Error_during_broker_selection_if_session_ID_is_empty": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithIgnoreSessionIDGeneration(), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), @@ -1587,7 +1587,7 @@ func TestGdmModel(t *testing.T) { msg: "no session ID returned by broker", }, }, - "Error during broker selection if encryption key is empty": { + "Error_during_broker_selection_if_encryption_key_is_empty": { client: pam_test.NewDummyClient(nil, append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithSelectBrokerReturn(&authd.SBResponse{SessionId: "session-id"}, nil), @@ -1607,7 +1607,7 @@ func TestGdmModel(t *testing.T) { msg: "no encryption key returned by broker", }, }, - "Error during broker selection if encryption key is not valid base64": { + "Error_during_broker_selection_if_encryption_key_is_not_valid_base64": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithSelectBrokerReturn(&authd.SBResponse{ @@ -1629,7 +1629,7 @@ func TestGdmModel(t *testing.T) { msg: "encryption key sent by broker is not a valid base64 encoded string: illegal base64 data at input byte 2", }, }, - "Error during broker selection if encryption key is not valid key": { + "Error_during_broker_selection_if_encryption_key_is_not_valid_key": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithSelectBrokerReturn(&authd.SBResponse{ @@ -1652,7 +1652,7 @@ func TestGdmModel(t *testing.T) { msg: gdmTestIgnoredMessage, }, }, - "Error during broker auth mode selection if UI is not valid": { + "Error_during_broker_auth_mode_selection_if_UI_is_not_valid": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithUILayout(passwordUILayoutID, "", nil), ), @@ -1683,7 +1683,7 @@ func TestGdmModel(t *testing.T) { msg: "invalid empty UI Layout information from broker", }, }, - "Error on missing authentication modes": { + "Error_on_missing_authentication_modes": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetAuthenticationModesReturn([]*authd.GAMResponse_AuthenticationMode{}, nil), ), @@ -1714,7 +1714,7 @@ func TestGdmModel(t *testing.T) { msg: "no supported authentication mode available for this provider", }, }, - "Error on authentication mode selection": { + "Error_on_authentication_mode_selection": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithSelectAuthenticationModeReturn(nil, errors.New("error selecting auth mode")), ), @@ -1744,7 +1744,7 @@ func TestGdmModel(t *testing.T) { msg: "can't select authentication mode: error selecting auth mode", }, }, - "Error on invalid auth-mode layout type": { + "Error_on_invalid_auth-mode_layout_type": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithSelectAuthenticationModeReturn(&authd.UILayout{ Type: "invalid layout", @@ -1781,7 +1781,7 @@ func TestGdmModel(t *testing.T) { msg: `Sending GDM event failed: Conversation error: unknown layout type: "invalid layout"`, }, }, - "Error on authentication client failure": { + "Error_on_authentication_client_failure": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithIsAuthenticatedReturn(nil, errors.New("some authentication error")), ), @@ -1818,7 +1818,7 @@ func TestGdmModel(t *testing.T) { msg: "authentication status failure: some authentication error", }, }, - "Error on authentication client invalid message": { + "Error_on_authentication_client_invalid_message": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithIsAuthenticatedReturn(&authd.IAResponse{ @@ -1853,7 +1853,7 @@ func TestGdmModel(t *testing.T) { msg: "invalid json data from provider: invalid character 'i' looking for beginning of value", }, }, - "Error on authentication client denied because of wrong password - with error message": { + "Error_on_authentication_client_denied_because_of_wrong_password_-_with_error_message": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithIsAuthenticatedWantChallenge("gdm-good-password"), pam_test.WithIsAuthenticatedMessage("you're not allowed!"), @@ -1901,7 +1901,7 @@ func TestGdmModel(t *testing.T) { msg: "you're not allowed!", }, }, - "Error on authentication client denied because of wrong password": { + "Error_on_authentication_client_denied_because_of_wrong_password": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithIsAuthenticatedWantChallenge("gdm-good-password"), ), @@ -1945,7 +1945,7 @@ func TestGdmModel(t *testing.T) { msg: "Access denied", }, }, - "Error on authentication client denied because of wrong password after retry": { + "Error_on_authentication_client_denied_because_of_wrong_password_after_retry": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithIsAuthenticatedWantChallenge("gdm-good-password"), @@ -1992,7 +1992,7 @@ func TestGdmModel(t *testing.T) { msg: "Access denied", }, }, - "Error on authentication client because of empty auth data access": { + "Error_on_authentication_client_because_of_empty_auth_data_access": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithIsAuthenticatedReturn(&authd.IAResponse{}, nil), @@ -2034,7 +2034,7 @@ func TestGdmModel(t *testing.T) { msg: `Access "" is not valid`, }, }, - "Error on authentication client because of invalid auth data access with message": { + "Error_on_authentication_client_because_of_invalid_auth_data_access_with_message": { clientOptions: append(slices.Clone(singleBrokerClientOptions), pam_test.WithGetPreviousBrokerReturn(firstBrokerInfo.Id, nil), pam_test.WithIsAuthenticatedReturn(&authd.IAResponse{ @@ -2079,7 +2079,7 @@ func TestGdmModel(t *testing.T) { msg: `Access "no way you get here!" is not valid`, }, }, - "Error on change stage using an unknown stage": { + "Error_on_change_stage_using_an_unknown_stage": { gdmEvents: []*gdm.EventData{ gdm_test.ChangeStageEvent(gdmTestIgnoreStage), }, @@ -2106,7 +2106,7 @@ func TestGdmModel(t *testing.T) { msg: `unknown PAM stage: "-1"`, }, }, - "Error during hello conversation": { + "Error_during_hello_conversation": { convError: map[string]error{ gdm_test.DataToJSON(t, &gdm.Data{ Type: gdm.DataType_hello, @@ -2117,14 +2117,14 @@ func TestGdmModel(t *testing.T) { msg: "GDM initialization failed: Conversation error: this is an hello error", }, }, - "Error during hello on protocol mismatch": { + "Error_during_hello_on_protocol_mismatch": { protoVersion: 99999999, wantExitStatus: pamError{ status: pam.ErrCredUnavail, msg: "GDM protocol initialization failed, type hello, version 99999999", }, }, - "Error during poll": { + "Error_during_poll": { convError: map[string]error{ gdm_test.DataToJSON(t, &gdm.Data{Type: gdm.DataType_poll}): errors.New("this is a poll error"), }, @@ -2133,7 +2133,7 @@ func TestGdmModel(t *testing.T) { msg: "Sending GDM poll failed: Conversation error: this is a poll error", }, }, - "Error on change stage": { + "Error_on_change_stage": { convError: map[string]error{ gdm_test.DataToJSON(t, &gdm.Data{ Type: gdm.DataType_request, @@ -2155,7 +2155,7 @@ func TestGdmModel(t *testing.T) { msg: "Changing GDM stage failed: Conversation error: this is a stage change error", }, }, - "Error on request UI capabilities": { + "Error_on_request_UI_capabilities": { convError: map[string]error{ gdm_test.DataToJSON(t, &gdm.Data{ Type: gdm.DataType_request, @@ -2171,7 +2171,7 @@ func TestGdmModel(t *testing.T) { msg: "Sending GDM UI capabilities Request failed: Conversation error: this is an UI capabilities request error", }, }, - "Error on selecting user name after PAM provided already one": { + "Error_on_selecting_user_name_after_PAM_provided_already_one": { pamUser: "gdm-pam-preset-user", messages: []tea.Msg{ tea.Sequence(tea.Tick(gdmPollFrequency*2, func(t time.Time) tea.Msg { diff --git a/pam/internal/dbusmodule/transaction_test.go b/pam/internal/dbusmodule/transaction_test.go index 19f7caebd..34e21d345 100644 --- a/pam/internal/dbusmodule/transaction_test.go +++ b/pam/internal/dbusmodule/transaction_test.go @@ -48,38 +48,38 @@ func TestTransactionSetEnv(t *testing.T) { wantMethodCall methodCall wantError error }{ - "Sets an env": { + "Sets_an_env": { env: "ENV=foo", methodReturns: methodReturn{m: setMethodName, values: []any{0}}, wantMethodCall: methodCall{setMethodName, []any{"ENV", "foo"}}, }, - "Sets an empty env": { + "Sets_an_empty_env": { env: "ENV=", methodReturns: methodReturn{m: setMethodName, values: []any{0}}, wantMethodCall: methodCall{setMethodName, []any{"ENV", ""}}, }, - "Unsets an env": { + "Unsets_an_env": { env: "ENV", methodReturns: methodReturn{m: unsetMethodName, values: []any{0}}, wantMethodCall: methodCall{unsetMethodName, []any{"ENV"}}, }, // Error cases - "Errors when setting an env, receiving a DBus error": { + "Errors_when_setting_an_env,_receiving_a_DBus_error": { env: "ENV=foo", wantError: pam.ErrSystem, }, - "Errors when setting an env, receiving a PAM error": { + "Errors_when_setting_an_env,_receiving_a_PAM_error": { env: "ENV=foo", methodReturns: methodReturn{m: setMethodName, values: []any{pam.ErrBadItem}}, wantMethodCall: methodCall{setMethodName, []any{"ENV", "foo"}}, wantError: pam.ErrBadItem, }, - "Errors when unsetting an env, receiving a DBus error": { + "Errors_when_unsetting_an_env,_receiving_a_DBus_error": { env: "ENV", wantError: pam.ErrSystem, }, - "Errors when unsetting an env, receiving a PAM error": { + "Errors_when_unsetting_an_env,_receiving_a_PAM_error": { env: "ENV", methodReturns: methodReturn{m: unsetMethodName, values: []any{pam.ErrAbort}}, wantMethodCall: methodCall{unsetMethodName, []any{"ENV"}}, @@ -114,12 +114,12 @@ func TestTransactionGetEnv(t *testing.T) { wantMethodCall methodCall wantValue string }{ - "Gets an empty env": { + "Gets_an_empty_env": { env: "ENV", wantMethodCall: methodCall{methodName, []any{"ENV"}}, methodReturns: methodReturn{m: methodName, values: []any{0, ""}}, }, - "Gets an value env": { + "Gets_an_value_env": { env: "ENV", wantMethodCall: methodCall{methodName, []any{"ENV"}}, methodReturns: methodReturn{m: methodName, values: []any{0, "some-value"}}, @@ -127,10 +127,10 @@ func TestTransactionGetEnv(t *testing.T) { }, // Error cases - "Errors when getting an env, receiving a DBus error": { + "Errors_when_getting_an_env,_receiving_a_DBus_error": { env: "ENV", }, - "Errors when getting an env, receiving a PAM error": { + "Errors_when_getting_an_env,_receiving_a_PAM_error": { env: "ENV", wantMethodCall: methodCall{methodName, []any{"ENV", "foo"}}, methodReturns: methodReturn{m: methodName, values: []any{pam.ErrIncomplete, "some-value"}}, @@ -161,22 +161,22 @@ func TestTransactionGetEnvList(t *testing.T) { wantEnvList map[string]string wantError error }{ - "Gets an empty env list": { + "Gets_an_empty_env_list": { wantMethodCall: methodCall{m: methodName}, methodReturns: methodReturn{m: methodName, values: []any{0, map[string]string{}}}, wantEnvList: map[string]string{}, }, - "Gets a filled env list": { + "Gets_a_filled_env_list": { wantMethodCall: methodCall{m: methodName}, methodReturns: methodReturn{m: methodName, values: []any{0, someEnvList}}, wantEnvList: someEnvList, }, // Error cases - "Errors when getting an env list, receiving a DBus error": { + "Errors_when_getting_an_env_list,_receiving_a_DBus_error": { wantError: pam.ErrSystem, }, - "Errors when getting an env, receiving a PAM error": { + "Errors_when_getting_an_env,_receiving_a_PAM_error": { wantMethodCall: methodCall{m: methodName}, methodReturns: methodReturn{m: methodName, values: []any{pam.ErrBuf, someEnvList}}, wantError: pam.ErrBuf, @@ -212,13 +212,13 @@ func TestTransactionSetItem(t *testing.T) { wantMethodCall methodCall wantError error }{ - "Sets an item": { + "Sets_an_item": { item: pam.User, value: "user", methodReturns: methodReturn{m: methodName, values: []any{0}}, wantMethodCall: methodCall{methodName, []any{pam.User, "user"}}, }, - "Sets an empty item": { + "Sets_an_empty_item": { item: pam.Rhost, value: "", methodReturns: methodReturn{m: methodName, values: []any{0}}, @@ -226,11 +226,11 @@ func TestTransactionSetItem(t *testing.T) { }, // Error cases - "Errors when setting an item, receiving a DBus error": { + "Errors_when_setting_an_item,_receiving_a_DBus_error": { value: "item", wantError: pam.ErrSystem, }, - "Errors when setting an item, receiving a PAM error": { + "Errors_when_setting_an_item,_receiving_a_PAM_error": { item: pam.User, value: "user", methodReturns: methodReturn{m: methodName, values: []any{pam.ErrBadItem}}, @@ -267,13 +267,13 @@ func TestTransactionGetItem(t *testing.T) { wantValue string wantError error }{ - "Gets an item": { + "Gets_an_item": { item: pam.User, wantValue: "user", methodReturns: methodReturn{m: methodName, values: []any{0, "user"}}, wantMethodCall: methodCall{methodName, []any{pam.User}}, }, - "Gets an empty item": { + "Gets_an_empty_item": { item: pam.Rhost, wantValue: "", methodReturns: methodReturn{m: methodName, values: []any{0, ""}}, @@ -281,11 +281,11 @@ func TestTransactionGetItem(t *testing.T) { }, // Error cases - "Errors when getting an item, receiving a DBus error": { + "Errors_when_getting_an_item,_receiving_a_DBus_error": { item: pam.Item(-1), wantError: pam.ErrSystem, }, - "Errors when getting an item, receiving a PAM error": { + "Errors_when_getting_an_item,_receiving_a_PAM_error": { item: pam.Item(-1), methodReturns: methodReturn{m: methodName, values: []any{pam.ErrBadItem, "user"}}, wantMethodCall: methodCall{methodName, []any{pam.Item(-1)}}, @@ -325,13 +325,13 @@ func TestTransactionSetData(t *testing.T) { wantMethodCall methodCall wantError error }{ - "Sets some data": { + "Sets_some_data": { key: "data", data: testData, methodReturns: methodReturn{m: setMethodName, values: []any{0}}, wantMethodCall: methodCall{setMethodName, []any{"data", variantTestData}}, }, - "Unsets some data": { + "Unsets_some_data": { key: "data-to-unset", data: nil, methodReturns: methodReturn{m: unsetMethodName, values: []any{0}}, @@ -339,23 +339,23 @@ func TestTransactionSetData(t *testing.T) { }, // Error cases - "Errors when setting data, receiving a DBus error": { + "Errors_when_setting_data,_receiving_a_DBus_error": { key: "data", data: testData, wantError: pam.ErrSystem, }, - "Errors when setting data, receiving a PAM error": { + "Errors_when_setting_data,_receiving_a_PAM_error": { key: "data", data: testData, methodReturns: methodReturn{m: setMethodName, values: []any{pam.ErrBuf}}, wantMethodCall: methodCall{setMethodName, []any{"data", variantTestData}}, wantError: pam.ErrBuf, }, - "Errors when unsetting data, receiving a DBus error": { + "Errors_when_unsetting_data,_receiving_a_DBus_error": { key: "data", wantError: pam.ErrSystem, }, - "Errors when unsetting data, receiving a PAM error": { + "Errors_when_unsetting_data,_receiving_a_PAM_error": { key: "data-to-unset", data: nil, methodReturns: methodReturn{m: unsetMethodName, values: []any{pam.ErrAbort}}, @@ -394,7 +394,7 @@ func TestTransactionGetData(t *testing.T) { wantData any wantError error }{ - "Gets some data": { + "Gets_some_data": { key: "data", wantData: testData, methodReturns: methodReturn{m: methodName, values: []any{0, variantTestData}}, @@ -402,11 +402,11 @@ func TestTransactionGetData(t *testing.T) { }, // Error cases - "Errors when getting data, receiving a DBus error": { + "Errors_when_getting_data,_receiving_a_DBus_error": { key: "data", wantError: pam.ErrSystem, }, - "Errors when getting data, receiving a PAM error": { + "Errors_when_getting_data,_receiving_a_PAM_error": { key: "data", methodReturns: methodReturn{m: methodName, values: []any{pam.ErrNoModuleData, variantTestData}}, wantMethodCall: methodCall{methodName, []any{"data"}}, @@ -446,12 +446,12 @@ func TestStartStringConv(t *testing.T) { wantMethodCalls *methodCallExpectations wantError error }{ - "Messages with error style are handled by conversation": { + "Messages_with_error_style_are_handled_by_conversation": { prompt: "This is an error!", convStyle: pam.ErrorMsg, want: "I'm handling it fine though", }, - "Conversation prompt can be formatted": { + "Conversation_prompt_can_be_formatted": { promptFormat: "Sending some %s, right? %v", promptFormatArgs: []interface{}{"info", true}, convStyle: pam.TextInfo, @@ -459,17 +459,17 @@ func TestStartStringConv(t *testing.T) { }, // Error cases - "Error if conversation receives a DBus error": { + "Error_if_conversation_receives_a_DBus_error": { wantError: pam.ErrSystem, convShouldNotBeCalled: true, }, - "Error if the conversation handler fails": { + "Error_if_the_conversation_handler_fails": { prompt: "Tell me your secret!", convStyle: pam.PromptEchoOff, convError: pam.ErrBuf, wantError: pam.ErrBuf, }, - "Error when conversation uses binary content style": { + "Error_when_conversation_uses_binary_content_style": { prompt: "I am a binary content\xff!", convStyle: pam.BinaryPrompt, convError: pam.ErrConv, @@ -531,27 +531,27 @@ func TestTransactionGetUser(t *testing.T) { want string wantError error }{ - "Getting a previously set user does not require conversation handler": { + "Getting_a_previously_set_user_does_not_require_conversation_handler": { presetUser: "an-user", want: "an-user", }, - "Getting a previously set user does not use conversation handler": { + "Getting_a_previously_set_user_does_not_use_conversation_handler": { presetUser: "an-user", convUser: "another-user", want: "an-user", }, - "Getting the user uses conversation handler if none was set": { + "Getting_the_user_uses_conversation_handler_if_none_was_set": { want: "provided-user", convUser: "provided-user", }, // Error cases - "Error when can't get user item": { + "Error_when_can't_get_user_item": { want: "", getError: pam.ErrBadItem, wantError: pam.ErrBadItem, }, - "Error when conversation fails": { + "Error_when_conversation_fails": { want: "", convError: pam.ErrConv, wantError: pam.ErrConv, @@ -588,7 +588,7 @@ func TestStartBinaryConv(t *testing.T) { wantError error }{ // Error cases - "Error as they are not supported": { + "Error_as_they_are_not_supported": { wantError: pam.ErrConv, }, } diff --git a/pam/internal/gdm/conversation_test.go b/pam/internal/gdm/conversation_test.go index 2181c4c85..5e792675d 100644 --- a/pam/internal/gdm/conversation_test.go +++ b/pam/internal/gdm/conversation_test.go @@ -25,40 +25,40 @@ func TestSendToGdm(t *testing.T) { wantError error wantConvHandlerNotToBeCalled bool }{ - "JSON null data can be sent and received": { + "JSON_null_data_can_be_sent_and_received": { value: []byte(`null`), }, - "JSON number can be sent and received": { + "JSON_number_can_be_sent_and_received": { value: []byte(`1.5`), }, - "Single char is sent and received as string": { + "Single_char_is_sent_and_received_as_string": { value: []byte(`"m"`), }, - "JSON null is returned": { + "JSON_null_is_returned": { value: []byte(`"give me 🚫"`), wantReturn: []byte("null"), }, - "Utf-8 data is sent and returned": { + "Utf-8_data_is_sent_and_returned": { value: []byte(`"give me 🍕"`), wantReturn: []byte(`"😋"`), }, - "Nil data returned": { + "Nil_data_returned": { value: []byte(`"give me 🚫"`), wantReturn: []byte(nil), }, // Error cases - "Error on empty data": { + "Error_on_empty_data": { value: []byte{}, wantError: ErrInvalidJSON, wantConvHandlerNotToBeCalled: true, }, - "Error on nil data": { + "Error_on_nil_data": { value: nil, wantError: ErrInvalidJSON, wantConvHandlerNotToBeCalled: true, }, - "Error with empty data returned": { + "Error_with_empty_data_returned": { value: []byte(`"give me 🗑‼"`), wantReturn: []byte{}, wantError: ErrInvalidJSON, @@ -114,7 +114,7 @@ func TestSendData(t *testing.T) { wantError error wantConvHandlerNotToBeCalled bool }{ - "Send data can handle null JSON value as return value": { + "Send_data_can_handle_null_JSON_value_as_return_value": { value: &Data{ Type: DataType_event, Event: &EventData{ @@ -125,7 +125,7 @@ func TestSendData(t *testing.T) { wantReturn: []byte("null"), }, - "Can send Hello packet data": { + "Can_send_Hello_packet_data": { value: &Data{ Type: DataType_hello, Hello: &HelloData{Version: 12345}, @@ -134,13 +134,13 @@ func TestSendData(t *testing.T) { }, // Error cases - "Error on empty data": { + "Error_on_empty_data": { value: &Data{}, wantConvHandlerNotToBeCalled: true, wantReturn: nil, wantError: errors.New("unexpected type unknownType"), }, - "Error on missing data return": { + "Error_on_missing_data_return": { value: &Data{ Type: DataType_event, Event: &EventData{ @@ -152,7 +152,7 @@ func TestSendData(t *testing.T) { wantConvHandlerNotToBeCalled: true, wantError: errors.New("missing event data"), }, - "Error on wrong data": { + "Error_on_wrong_data": { value: &Data{ Type: DataType_event, Request: &RequestData{}, @@ -222,7 +222,7 @@ func TestDataConversationFunc(t *testing.T) { wantError error wantConvHandlerNotToBeCalled bool }{ - "Send valid data and return it back": { + "Send_valid_data_and_return_it_back": { inData: &Data{ Type: DataType_hello, Hello: &HelloData{Version: 12345}, @@ -232,7 +232,7 @@ func TestDataConversationFunc(t *testing.T) { }, // Error cases - "Error on invalid protocol": { + "Error_on_invalid_protocol": { mayHitLeakSanitizer: true, inBinReq: func() pam.BinaryConvRequester { if pam_test.IsAddressSanitizerActive() { @@ -246,7 +246,7 @@ func TestDataConversationFunc(t *testing.T) { wantConvHandlerNotToBeCalled: true, wantError: ErrProtoNotSupported, }, - "Error on unexpected JSON": { + "Error_on_unexpected_JSON": { mayHitLeakSanitizer: true, inBinReq: func() pam.BinaryConvRequester { if pam_test.IsAddressSanitizerActive() { @@ -259,7 +259,7 @@ func TestDataConversationFunc(t *testing.T) { wantConvHandlerNotToBeCalled: true, wantError: errors.New("syntax error"), }, - "Error on invalid Returned Data": { + "Error_on_invalid_Returned_Data": { inData: &Data{ Type: DataType_hello, Hello: &HelloData{Version: 12345}, @@ -336,14 +336,14 @@ func TestDataSendChecked(t *testing.T) { wantError error wantConvHandlerNotToBeCalled bool }{ - "Can send and receive Hello packet data": { + "Can_send_and_receive_Hello_packet_data": { value: &Data{ Type: DataType_hello, Hello: &HelloData{Version: 12345}, }, wantReturn: &Data{Type: DataType_hello}, }, - "Can send event and receive an event ack": { + "Can_send_event_and_receive_an_event_ack": { value: &Data{ Type: DataType_event, Event: &EventData{ @@ -356,13 +356,13 @@ func TestDataSendChecked(t *testing.T) { }, // Error cases - "Error on empty data": { + "Error_on_empty_data": { value: &Data{}, wantConvHandlerNotToBeCalled: true, wantReturn: nil, wantError: errors.New("unexpected type unknownType"), }, - "Error on missing data return": { + "Error_on_missing_data_return": { value: &Data{ Type: DataType_event, Event: &EventData{ @@ -373,7 +373,7 @@ func TestDataSendChecked(t *testing.T) { wantConvHandlerNotToBeCalled: true, wantError: errors.New("missing event data"), }, - "Error on wrong data": { + "Error_on_wrong_data": { value: &Data{ Type: DataType_event, Request: &RequestData{}, @@ -428,18 +428,18 @@ func TestDataSendPoll(t *testing.T) { wantError error wantConvHandlerNotToBeCalled bool }{ - "Polling handles a null response": { + "Polling_handles_a_null_response": { wantReturn: &Data{ Type: DataType_pollResponse, }, }, - "Polling handles an empty response": { + "Polling_handles_an_empty_response": { wantReturn: &Data{ Type: DataType_pollResponse, PollResponse: []*EventData{}, }, }, - "Polling handles multiple event events response": { + "Polling_handles_multiple_event_events_response": { wantReturn: &Data{ Type: DataType_pollResponse, PollResponse: []*EventData{ @@ -451,11 +451,11 @@ func TestDataSendPoll(t *testing.T) { }, // Error cases - "Error on nil return": { + "Error_on_nil_return": { wantReturn: nil, wantError: errors.New("unexpected token null"), }, - "Error on unexpected type": { + "Error_on_unexpected_type": { wantReturn: &Data{Type: DataType_hello}, wantError: errors.New("gdm replied with an unexpected type: hello"), }, @@ -541,7 +541,7 @@ func TestDataSendRequestTyped(t *testing.T) { wantConvHandlerNotToBeCalled bool wantReturnType any }{ - "Request change state": { + "Request_change_state": { request: &RequestData_ChangeStage{}, wantData: &Data{ Type: DataType_response, @@ -551,7 +551,7 @@ func TestDataSendRequestTyped(t *testing.T) { }, }, }, - "Request Ui layout capabilities": { + "Request_Ui_layout_capabilities": { request: &RequestData_UiLayoutCapabilities{}, wantData: &Data{ Type: DataType_response, @@ -561,7 +561,7 @@ func TestDataSendRequestTyped(t *testing.T) { }, }, }, - "Request change state, handles nil response data": { + "Request_change_state,_handles_nil_response_data": { request: &RequestData_ChangeStage{}, wantData: &Data{ Type: DataType_response, @@ -571,7 +571,7 @@ func TestDataSendRequestTyped(t *testing.T) { }, }, }, - "Request Ui layout capabilities, handles nil response data": { + "Request_Ui_layout_capabilities,_handles_nil_response_data": { request: &RequestData_UiLayoutCapabilities{}, wantData: &Data{ Type: DataType_response, @@ -581,7 +581,7 @@ func TestDataSendRequestTyped(t *testing.T) { }, }, }, - "Request change state, expecting Ack type": { + "Request_change_state,_expecting_Ack_type": { request: &RequestData_ChangeStage{}, wantData: &Data{ Type: DataType_response, @@ -592,7 +592,7 @@ func TestDataSendRequestTyped(t *testing.T) { }, wantReturnType: &ResponseData_Ack{}, }, - "Request Ui layout capabilities, expecting Ack type": { + "Request_Ui_layout_capabilities,_expecting_Ack_type": { request: &RequestData_UiLayoutCapabilities{}, wantData: &Data{ Type: DataType_response, @@ -604,7 +604,7 @@ func TestDataSendRequestTyped(t *testing.T) { wantError: errors.New("impossible to convert"), wantReturnType: &ResponseData_Ack{}, }, - "Request change state, handles nil response data, expecting Ack type": { + "Request_change_state,_handles_nil_response_data,_expecting_Ack_type": { request: &RequestData_ChangeStage{}, wantData: &Data{ Type: DataType_response, @@ -615,7 +615,7 @@ func TestDataSendRequestTyped(t *testing.T) { }, wantReturnType: &ResponseData_Ack{}, }, - "Request change state, expecting UiLayoutCapabilities type": { + "Request_change_state,_expecting_UiLayoutCapabilities_type": { request: &RequestData_ChangeStage{}, wantData: &Data{ Type: DataType_response, @@ -627,7 +627,7 @@ func TestDataSendRequestTyped(t *testing.T) { wantReturnType: &ResponseData_UiLayoutCapabilities{}, wantError: errors.New("impossible to convert"), }, - "Request Ui layout capabilities, handles nil response data, expecting UiLayoutCapabilities type": { + "Request_Ui_layout_capabilities,_handles_nil_response_data,_expecting_UiLayoutCapabilities_type": { request: &RequestData_UiLayoutCapabilities{}, wantData: &Data{ Type: DataType_response, @@ -638,7 +638,7 @@ func TestDataSendRequestTyped(t *testing.T) { }, wantReturnType: &ResponseData_UiLayoutCapabilities{}, }, - "Request Ui layout capabilities, expecting UiLayoutCapabilities type": { + "Request_Ui_layout_capabilities,_expecting_UiLayoutCapabilities_type": { request: &RequestData_UiLayoutCapabilities{}, wantData: &Data{ Type: DataType_response, @@ -659,18 +659,18 @@ func TestDataSendRequestTyped(t *testing.T) { }, // Error cases - "Error with unknown request": { + "Error_with_unknown_request": { request: &invalidRequest{}, wantConvHandlerNotToBeCalled: true, wantError: errors.New("no known request type"), }, // Error cases - "Error on nil return": { + "Error_on_nil_return": { request: &RequestData_ChangeStage{}, wantData: nil, wantError: errors.New("unexpected token null"), }, - "Error with mismatching response type": { + "Error_with_mismatching_response_type": { request: &RequestData_ChangeStage{}, wantData: &Data{ Type: DataType_response, @@ -678,20 +678,20 @@ func TestDataSendRequestTyped(t *testing.T) { }, wantError: errors.New("gdm replied with invalid response type"), }, - "Error with non-response type": { + "Error_with_non-response_type": { request: &RequestData_ChangeStage{}, wantData: &Data{ Type: DataType_hello, }, wantError: errors.New("gdm replied with an unexpected type: hello"), }, - "Error with unknown request expecting Ack type": { + "Error_with_unknown_request_expecting_Ack_type": { request: &invalidRequest{}, wantConvHandlerNotToBeCalled: true, wantError: errors.New("no known request type"), wantReturnType: &ResponseData_Ack{}, }, - "Error with mismatching response type expecting Ack type": { + "Error_with_mismatching_response_type_expecting_Ack_type": { request: &RequestData_ChangeStage{}, wantData: &Data{ Type: DataType_response, @@ -700,7 +700,7 @@ func TestDataSendRequestTyped(t *testing.T) { wantError: errors.New("gdm replied with invalid response type"), wantReturnType: &ResponseData_Ack{}, }, - "Error with non-response type expecting Ack type": { + "Error_with_non-response_type_expecting_Ack_type": { request: &RequestData_ChangeStage{}, wantData: &Data{ Type: DataType_hello, @@ -708,13 +708,13 @@ func TestDataSendRequestTyped(t *testing.T) { wantError: errors.New("gdm replied with an unexpected type: hello"), wantReturnType: &ResponseData_Ack{}, }, - "Error with unknown request expecting UiLayoutCapabilities type": { + "Error_with_unknown_request_expecting_UiLayoutCapabilities_type": { request: &invalidRequest{}, wantConvHandlerNotToBeCalled: true, wantError: errors.New("no known request type"), wantReturnType: &ResponseData_UiLayoutCapabilities{}, }, - "Error with mismatching response type expecting UiLayoutCapabilities type": { + "Error_with_mismatching_response_type_expecting_UiLayoutCapabilities_type": { request: &RequestData_ChangeStage{}, wantData: &Data{ Type: DataType_response, @@ -723,7 +723,7 @@ func TestDataSendRequestTyped(t *testing.T) { wantError: errors.New("gdm replied with invalid response type"), wantReturnType: &ResponseData_UiLayoutCapabilities{}, }, - "Error with non-response type expecting UiLayoutCapabilities type": { + "Error_with_non-response_type_expecting_UiLayoutCapabilities_type": { request: &RequestData_ChangeStage{}, wantData: &Data{ Type: DataType_hello, @@ -798,66 +798,66 @@ func TestDataEmitEvent(t *testing.T) { wantError error wantConvHandlerNotToBeCalled bool }{ - "Emit event BrokersReceived": { + "Emit_event_BrokersReceived": { event: &EventData_BrokersReceived{}, wantEventType: EventType_brokersReceived, }, - "Emit event BrokerSelected": { + "Emit_event_BrokerSelected": { event: &EventData_BrokerSelected{}, wantEventType: EventType_brokerSelected, }, - "Emit event AuthModesReceived": { + "Emit_event_AuthModesReceived": { event: &EventData_AuthModesReceived{}, wantEventType: EventType_authModesReceived, }, - "Emit event AuthModeSelected": { + "Emit_event_AuthModeSelected": { event: &EventData_AuthModeSelected{}, wantEventType: EventType_authModeSelected, }, - "Emit event IsAuthenticatedRequested": { + "Emit_event_IsAuthenticatedRequested": { event: &EventData_IsAuthenticatedRequested{}, wantEventType: EventType_isAuthenticatedRequested, }, - "Emit event IsAuthenticatedCancelled": { + "Emit_event_IsAuthenticatedCancelled": { event: &EventData_IsAuthenticatedCancelled{}, wantEventType: EventType_isAuthenticatedCancelled, }, - "Emit event StageChanged": { + "Emit_event_StageChanged": { event: &EventData_StageChanged{}, wantEventType: EventType_stageChanged, }, - "Emit event UiLayoutReceived": { + "Emit_event_UiLayoutReceived": { event: &EventData_UiLayoutReceived{}, wantEventType: EventType_uiLayoutReceived, }, - "Emit event AuthEvent": { + "Emit_event_AuthEvent": { event: &EventData_AuthEvent{}, wantEventType: EventType_authEvent, }, - "Emit event ReselectAuthMode": { + "Emit_event_ReselectAuthMode": { event: &EventData_ReselectAuthMode{}, wantEventType: EventType_reselectAuthMode, }, - "Emit event UserSelected": { + "Emit_event_UserSelected": { event: &EventData_UserSelected{}, wantEventType: EventType_userSelected, }, - "Emit event StartAuthentication": { + "Emit_event_StartAuthentication": { event: &EventData_StartAuthentication{}, wantEventType: EventType_startAuthentication, }, // Error cases - "Error on nil event": { + "Error_on_nil_event": { wantConvHandlerNotToBeCalled: true, wantError: errors.New("no known event type"), }, - "Error on unexpected event type": { + "Error_on_unexpected_event_type": { event: &invalidEvent{}, wantConvHandlerNotToBeCalled: true, wantError: fmt.Errorf("no known event type %#v", &invalidEvent{}), }, - "Error on invalid data": { + "Error_on_invalid_data": { event: &EventData_ReselectAuthMode{}, returnedData: []byte("null"), wantError: errors.New("unexpected token null"), diff --git a/pam/internal/gdm/extension_test.go b/pam/internal/gdm/extension_test.go index a1764082a..18dc8d8b9 100644 --- a/pam/internal/gdm/extension_test.go +++ b/pam/internal/gdm/extension_test.go @@ -32,16 +32,16 @@ func TestGdmExtensionSupport(t *testing.T) { checkExtensions []string supportedExtensions []string }{ - "Unknown extension is unsupported": { + "Unknown_extension_is_unsupported": { checkExtensions: []string{"foo.extension"}, supportedExtensions: nil, }, - "Extensions are advertised": { + "Extensions_are_advertised": { advertisedExtensions: []string{PamExtensionCustomJSON, "foo"}, checkExtensions: []string{PamExtensionCustomJSON, "foo"}, supportedExtensions: []string{PamExtensionCustomJSON, "foo"}, }, - "The private string extension unsupported if not advertised": { + "The_private_string_extension_unsupported_if_not_advertised": { checkExtensions: []string{PamExtensionCustomJSON}, supportedExtensions: nil, }, @@ -69,25 +69,25 @@ func TestGdmJSONProto(t *testing.T) { testCases := map[string]struct { value []byte }{ - "With null data": { + "With_null_data": { value: []byte("null"), }, - "With single int": { + "With_single_int": { value: []byte("55"), }, - "With single float": { + "With_single_float": { value: []byte("5.5"), }, - "With single string": { + "With_single_string": { value: []byte(`"hello"`), }, - "With single boolean": { + "With_single_boolean": { value: []byte("true"), }, - "With empty object": { + "With_empty_object": { value: []byte("{}"), }, - "With complex object": { + "With_complex_object": { value: []byte(`{"type":"pollResponse","pollResponse":` + `[{"type":"brokerSelected","brokerSelected":{"brokerId":"a broker"}},` + `{"type":"authModeSelected","authModeSelected":{"authModeId":"auth mode"}}]}`), @@ -120,16 +120,16 @@ func TestGdmJSONProtoRequestErrors(t *testing.T) { testCases := map[string]struct { value []byte }{ - "With empty data": { + "With_empty_data": { value: []byte{}, }, - "With null data": { + "With_null_data": { value: nil, }, - "With single char": { + "With_single_char": { value: []byte("m"), }, - "With lorem ipsum string data": { + "With_lorem_ipsum_string_data": { value: []byte(` Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, @@ -139,7 +139,7 @@ func TestGdmJSONProtoRequestErrors(t *testing.T) { non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. `), }, - "With invalid JSON object": { + "With_invalid_JSON_object": { value: []byte("{[,]}"), }, } @@ -166,31 +166,31 @@ func TestGdmJSONProtoResponseErrors(t *testing.T) { wantError error }{ - "On proto name mismatch": { + "On_proto_name_mismatch": { protoName: "some.other.protocol", protoVersion: JSONProtoVersion, jsonValue: []byte("null"), wantError: ErrProtoNotSupported, }, - "On proto version mismatch": { + "On_proto_version_mismatch": { protoName: JSONProtoName, protoVersion: JSONProtoVersion + 100, jsonValue: []byte("{}"), wantError: ErrProtoNotSupported, }, - "On nil JSON": { + "On_nil_JSON": { protoName: JSONProtoName, protoVersion: JSONProtoVersion, jsonValue: nil, wantError: ErrInvalidJSON, }, - "On empty JSON": { + "On_empty_JSON": { protoName: JSONProtoName, protoVersion: JSONProtoVersion, jsonValue: []byte{}, wantError: ErrInvalidJSON, }, - "On invalid JSON": { + "On_invalid_JSON": { protoName: JSONProtoName, protoVersion: JSONProtoVersion, jsonValue: []byte("{]"), diff --git a/pam/internal/gdm/protocol_test.go b/pam/internal/gdm/protocol_test.go index c5a0e4dee..42733e5ff 100644 --- a/pam/internal/gdm/protocol_test.go +++ b/pam/internal/gdm/protocol_test.go @@ -54,17 +54,17 @@ func TestGdmStructsMarshal(t *testing.T) { wantJSON string wantErrMsg string }{ - "Hello packet": { + "Hello_packet": { gdmData: &gdm.Data{Type: gdm.DataType_hello}, wantJSON: `{"type":"hello"}`, }, - "Hello packet with data": { + "Hello_packet_with_data": { gdmData: &gdm.Data{Type: gdm.DataType_hello, Hello: &gdm.HelloData{Version: 55}}, wantJSON: `{"type":"hello","hello":{"version":55}}`, }, - "Event packet": { + "Event_packet": { gdmData: &gdm.Data{ Type: gdm.DataType_event, Event: &gdm.EventData{ @@ -75,12 +75,12 @@ func TestGdmStructsMarshal(t *testing.T) { wantJSON: `{"type":"event","event":{"type":"brokerSelected","brokerSelected":{}}}`, }, - "Event ack packet": { + "Event_ack_packet": { gdmData: &gdm.Data{Type: gdm.DataType_eventAck}, wantJSON: `{"type":"eventAck"}`, }, - "Request packet": { + "Request_packet": { gdmData: &gdm.Data{ Type: gdm.DataType_request, Request: &gdm.RequestData{ @@ -91,7 +91,7 @@ func TestGdmStructsMarshal(t *testing.T) { wantJSON: `{"type":"request","request":{"type":"uiLayoutCapabilities","uiLayoutCapabilities":{}}}`, }, - "Request packet with missing data": { + "Request_packet_with_missing_data": { gdmData: &gdm.Data{ Type: gdm.DataType_request, Request: &gdm.RequestData{ @@ -101,7 +101,7 @@ func TestGdmStructsMarshal(t *testing.T) { wantJSON: `{"type":"request","request":{"type":"updateBrokersList"}}`, }, - "Response packet": { + "Response_packet": { gdmData: &gdm.Data{ Type: gdm.DataType_response, Response: &gdm.ResponseData{ @@ -112,7 +112,7 @@ func TestGdmStructsMarshal(t *testing.T) { wantJSON: `{"type":"response","response":{"type":"uiLayoutCapabilities","uiLayoutCapabilities":{}}}`, }, - "Response packet with ack data": { + "Response_packet_with_ack_data": { gdmData: &gdm.Data{ Type: gdm.DataType_response, Response: &gdm.ResponseData{ @@ -123,12 +123,12 @@ func TestGdmStructsMarshal(t *testing.T) { wantJSON: `{"type":"response","response":{"type":"changeStage","ack":{}}}`, }, - "Poll packet": { + "Poll_packet": { gdmData: &gdm.Data{Type: gdm.DataType_poll}, wantJSON: `{"type":"poll"}`, }, - "PollResponse packet": { + "PollResponse_packet": { gdmData: &gdm.Data{ Type: gdm.DataType_pollResponse, PollResponse: []*gdm.EventData{ @@ -144,7 +144,7 @@ func TestGdmStructsMarshal(t *testing.T) { wantJSON: `{"type":"pollResponse","pollResponse":` + `[{"type":"brokerSelected","brokerSelected":{"brokerId":"a broker"}}]}`, }, - "PollResponse packet with multiple results": { + "PollResponse_packet_with_multiple_results": { gdmData: &gdm.Data{ Type: gdm.DataType_pollResponse, PollResponse: []*gdm.EventData{ @@ -167,7 +167,7 @@ func TestGdmStructsMarshal(t *testing.T) { `[{"type":"brokerSelected","brokerSelected":{"brokerId":"a broker"}},` + `{"type":"authModeSelected","authModeSelected":{"authModeId":"auth mode"}}]}`, }, - "PollResponse packet with nil data": { + "PollResponse_packet_with_nil_data": { gdmData: &gdm.Data{ Type: gdm.DataType_pollResponse, PollResponse: nil, @@ -175,7 +175,7 @@ func TestGdmStructsMarshal(t *testing.T) { wantJSON: `{"type":"pollResponse"}`, }, - "PollResponse packet with empty data": { + "PollResponse_packet_with_empty_data": { gdmData: &gdm.Data{ Type: gdm.DataType_pollResponse, PollResponse: []*gdm.EventData{}, @@ -185,22 +185,22 @@ func TestGdmStructsMarshal(t *testing.T) { }, // Error cases - "Error empty packet": { + "Error_empty_packet": { gdmData: &gdm.Data{}, wantErrMsg: "unexpected type unknownType", }, - "Error if packet has invalid type": { + "Error_if_packet_has_invalid_type": { gdmData: &gdm.Data{Type: gdm.DataType(-1)}, wantErrMsg: "unhandled type -1", }, - "Error hello packet with unexpected data": { + "Error_hello_packet_with_unexpected_data": { gdmData: &gdm.Data{Type: gdm.DataType_hello, Request: &gdm.RequestData{}}, wantErrMsg: "field Request should not be defined", }, - "Error event packet with unknown type": { + "Error_event_packet_with_unknown_type": { gdmData: &gdm.Data{ Type: gdm.DataType_event, Event: &gdm.EventData{Type: gdm.EventType_unknownEvent}, @@ -208,27 +208,27 @@ func TestGdmStructsMarshal(t *testing.T) { wantErrMsg: "missing event type", }, - "Error event packet with invalid type": { + "Error_event_packet_with_invalid_type": { gdmData: &gdm.Data{Type: gdm.DataType_event, Event: &gdm.EventData{Type: gdm.EventType(-1)}}, wantErrMsg: "unexpected event type", }, - "Error event packet with missing data": { + "Error_event_packet_with_missing_data": { gdmData: &gdm.Data{Type: gdm.DataType_event, Event: nil}, wantErrMsg: "missing event data", }, - "Error event packet with empty data": { + "Error_event_packet_with_empty_data": { gdmData: &gdm.Data{Type: gdm.DataType_event, Event: &gdm.EventData{}}, wantErrMsg: "missing event type", }, - "Error event packet with missing type": { + "Error_event_packet_with_missing_type": { gdmData: &gdm.Data{Type: gdm.DataType_event, Event: &gdm.EventData{Data: &gdm.EventData_AuthModeSelected{}}}, wantErrMsg: "missing event type", }, - "Error event packet with unexpected data": { + "Error_event_packet_with_unexpected_data": { gdmData: &gdm.Data{ Type: gdm.DataType_event, Event: &gdm.EventData{Type: gdm.EventType_authEvent, Data: &gdm.EventData_AuthModeSelected{}}, @@ -237,31 +237,31 @@ func TestGdmStructsMarshal(t *testing.T) { wantErrMsg: "field Hello should not be defined", }, - "Error event ack packet with unexpected data": { + "Error_event_ack_packet_with_unexpected_data": { gdmData: &gdm.Data{Type: gdm.DataType_eventAck, Event: &gdm.EventData{}}, wantErrMsg: "field Event should not be defined", }, - "Error request packet with unknown type": { + "Error_request_packet_with_unknown_type": { gdmData: &gdm.Data{Type: gdm.DataType_request, Request: &gdm.RequestData{Data: &gdm.RequestData_ChangeStage{}}}, wantErrMsg: "missing request type", }, - "Error request packet with invalid type": { + "Error_request_packet_with_invalid_type": { gdmData: &gdm.Data{Type: gdm.DataType_request, Request: &gdm.RequestData{Type: gdm.RequestType(-1)}}, wantErrMsg: "unexpected request type", }, - "Error request packet with missing data": { + "Error_request_packet_with_missing_data": { gdmData: &gdm.Data{Type: gdm.DataType_request, Request: nil}, wantErrMsg: "missing request data", }, - "Error request packet with empty data": { + "Error_request_packet_with_empty_data": { gdmData: &gdm.Data{Type: gdm.DataType_request, Request: &gdm.RequestData{}}, wantErrMsg: "missing request type", }, - "Error request packet with unexpected data": { + "Error_request_packet_with_unexpected_data": { gdmData: &gdm.Data{ Type: gdm.DataType_request, Request: &gdm.RequestData{ @@ -273,12 +273,12 @@ func TestGdmStructsMarshal(t *testing.T) { wantErrMsg: "field Event should not be defined", }, - "Error response packet with missing data": { + "Error_response_packet_with_missing_data": { gdmData: &gdm.Data{Type: gdm.DataType_response}, wantErrMsg: "missing response data", }, - "Error response packet with missing type": { + "Error_response_packet_with_missing_type": { gdmData: &gdm.Data{ Type: gdm.DataType_response, Response: &gdm.ResponseData{Data: &gdm.ResponseData_Ack{}}, @@ -286,7 +286,7 @@ func TestGdmStructsMarshal(t *testing.T) { wantErrMsg: "missing response type", }, - "Error response packet with invalid type": { + "Error_response_packet_with_invalid_type": { gdmData: &gdm.Data{ Type: gdm.DataType_response, Response: &gdm.ResponseData{Type: gdm.RequestType(-1), Data: &gdm.ResponseData_Ack{}}, @@ -294,7 +294,7 @@ func TestGdmStructsMarshal(t *testing.T) { wantErrMsg: "unexpected request type -1", }, - "Error response packet with unexpected data": { + "Error_response_packet_with_unexpected_data": { gdmData: &gdm.Data{ Type: gdm.DataType_response, Response: &gdm.ResponseData{Type: gdm.RequestType_changeStage, Data: &gdm.ResponseData_Ack{}}, @@ -303,12 +303,12 @@ func TestGdmStructsMarshal(t *testing.T) { wantErrMsg: "field Event should not be defined", }, - "Error poll packet with unexpected data": { + "Error_poll_packet_with_unexpected_data": { gdmData: &gdm.Data{Type: gdm.DataType_poll, Request: &gdm.RequestData{}}, wantErrMsg: "field Request should not be defined", }, - "Error pollResponse packet with missing event type": { + "Error_pollResponse_packet_with_missing_event_type": { gdmData: &gdm.Data{ Type: gdm.DataType_pollResponse, PollResponse: []*gdm.EventData{ @@ -328,7 +328,7 @@ func TestGdmStructsMarshal(t *testing.T) { wantErrMsg: "poll response data member 1 invalid: missing event type", }, - "Error pollResponse packet with event with missing type": { + "Error_pollResponse_packet_with_event_with_missing_type": { gdmData: &gdm.Data{ Type: gdm.DataType_pollResponse, PollResponse: []*gdm.EventData{ @@ -344,7 +344,7 @@ func TestGdmStructsMarshal(t *testing.T) { wantErrMsg: "poll response data member 0 invalid: missing event type", }, - "Error pollResponse packet with unexpected data": { + "Error_pollResponse_packet_with_unexpected_data": { gdmData: &gdm.Data{ Type: gdm.DataType_pollResponse, PollResponse: []*gdm.EventData{}, @@ -385,17 +385,17 @@ func TestGdmStructsUnMarshal(t *testing.T) { wantData *gdm.Data wantErrMsg string }{ - "hello packet": { + "hello_packet": { JSON: `{"type":"hello"}`, wantData: &gdm.Data{Type: gdm.DataType_hello}, }, - "Hello packet with data": { + "Hello_packet_with_data": { JSON: `{"type":"hello","hello":{"version":55}}`, wantData: &gdm.Data{Type: gdm.DataType_hello, Hello: &gdm.HelloData{Version: 55}}, }, - "Event packet": { + "Event_packet": { JSON: `{"type":"event","event":{"type":"brokerSelected","brokerSelected":{}}}`, wantData: &gdm.Data{ @@ -406,12 +406,12 @@ func TestGdmStructsUnMarshal(t *testing.T) { }, }, }, - "Event ack packet": { + "Event_ack_packet": { JSON: `{"type":"eventAck"}`, wantData: &gdm.Data{Type: gdm.DataType_eventAck}, }, - "Request packet": { + "Request_packet": { JSON: `{"type":"request","request":{"type":"uiLayoutCapabilities","uiLayoutCapabilities":{}}}`, wantData: &gdm.Data{ @@ -422,7 +422,7 @@ func TestGdmStructsUnMarshal(t *testing.T) { }, }, }, - "Request packet with missing data": { + "Request_packet_with_missing_data": { JSON: `{"type":"request","request":{"type":"updateBrokersList"}}`, wantData: &gdm.Data{ @@ -432,7 +432,7 @@ func TestGdmStructsUnMarshal(t *testing.T) { }, }, }, - "Response packet": { + "Response_packet": { JSON: `{"type":"response","response":{"type":"uiLayoutCapabilities","uiLayoutCapabilities":{}}}`, wantData: &gdm.Data{ @@ -443,7 +443,7 @@ func TestGdmStructsUnMarshal(t *testing.T) { }, }, }, - "Response packet with ack data": { + "Response_packet_with_ack_data": { JSON: `{"type":"response","response":{"type":"changeStage","ack":{}}}`, wantData: &gdm.Data{ @@ -454,12 +454,12 @@ func TestGdmStructsUnMarshal(t *testing.T) { }, }, }, - "Poll packet": { + "Poll_packet": { JSON: `{"type":"poll"}`, wantData: &gdm.Data{Type: gdm.DataType_poll}, }, - "PollResponse packet": { + "PollResponse_packet": { JSON: `{"type":"pollResponse","pollResponse":` + `[{"type":"brokerSelected","brokerSelected":{"brokerId":"a broker"}}]}`, @@ -475,7 +475,7 @@ func TestGdmStructsUnMarshal(t *testing.T) { }, }, }, - "PollResponse packet with missing data": { + "PollResponse_packet_with_missing_data": { JSON: `{"type":"pollResponse"}`, wantData: &gdm.Data{ @@ -485,116 +485,116 @@ func TestGdmStructsUnMarshal(t *testing.T) { }, // Error cases - "Error empty packet ": { + "Error_empty_packet": { wantErrMsg: "syntax error", }, - "Error empty packet object": { + "Error_empty_packet_object": { JSON: `{}`, wantErrMsg: "unexpected type unknownType", }, - "Error packet with invalid type": { + "Error_packet_with_invalid_type": { JSON: `{"type":"invalidType"}`, wantErrMsg: "invalid value for enum field type", }, - "Error packet with invalid value type": { + "Error_packet_with_invalid_value_type": { JSON: `{"type":[]}`, wantErrMsg: "invalid value for enum field type", }, - "Error hello packet with unexpected data": { + "Error_hello_packet_with_unexpected_data": { JSON: `{"type":"hello","request":{}}`, wantErrMsg: "field Request should not be defined", }, - "Error event packet with invalid data": { + "Error_event_packet_with_invalid_data": { JSON: `{"type":"event","fooEvent":null}`, wantErrMsg: `unknown field "fooEvent"`, }, - "Error event packet with missing type": { + "Error_event_packet_with_missing_type": { JSON: `{"type":"event","event":{}}`, wantErrMsg: "missing event type", }, - "Error event packet with unknown type": { + "Error_event_packet_with_unknown_type": { JSON: `{"type":"event","event":{"type":"someType"}`, wantErrMsg: "invalid value for enum field type", }, - "Error event packet with invalid value type": { + "Error_event_packet_with_invalid_value_type": { JSON: `{"type":"event","event":{"brokerSelected":{},"type":{}}}`, wantErrMsg: "invalid value for enum field type", }, - "Error event packet with missing data": { + "Error_event_packet_with_missing_data": { JSON: `{"type":"event","event":{"type":"brokerSelected"}}`, wantErrMsg: "missing event data", }, - "Error event packet with unexpected data": { + "Error_event_packet_with_unexpected_data": { JSON: `{"type":"event","event":{"type":"brokerSelected",` + `"brokerSelected":{}},"request":{}}`, wantErrMsg: "field Request should not be defined", }, - "Error event ack packet with unexpected member": { + "Error_event_ack_packet_with_unexpected_member": { JSON: `{"type":"eventAck","event":{}}`, wantErrMsg: "field Event should not be defined", }, - "Error request packet with missing type": { + "Error_request_packet_with_missing_type": { JSON: `{"type":"request","request":{"uiLayoutCapabilities":{}}}`, wantErrMsg: "missing request type", }, - "Error request packet with unknown type": { + "Error_request_packet_with_unknown_type": { JSON: `{"type":"request","request":{"type":true,"uiLayoutCapabilities":{}}}`, wantErrMsg: "invalid value for enum field type", }, - "Error request packet with unknown value type": { + "Error_request_packet_with_unknown_value_type": { JSON: `{"type":"request","request":{"type":"someUnknownRequest",` + `"uiLayoutCapabilities":{}}}`, wantErrMsg: "invalid value for enum field type", }, - "Error request packet with unexpected data": { + "Error_request_packet_with_unexpected_data": { JSON: `{"type":"request","request":{"type": "uiLayoutCapabilities",` + `"uiLayoutCapabilities":{}}, "event":{}}`, wantErrMsg: "field Event should not be defined", }, - "Error response packet with missing data": { + "Error_response_packet_with_missing_data": { JSON: `{"type":"response"}`, wantErrMsg: "missing response data", }, - "Error response packet with unexpected data": { + "Error_response_packet_with_unexpected_data": { JSON: `{"type":"response","response":{"type":"changeStage","ack":{}}, "event":{}}`, wantErrMsg: "field Event should not be defined", }, - "Error poll packet with unexpected data": { + "Error_poll_packet_with_unexpected_data": { JSON: `{"type":"poll", "response": {}}`, wantErrMsg: "field Response should not be defined", }, - "Error pollResponse packet with missing event type": { + "Error_pollResponse_packet_with_missing_event_type": { JSON: `{"type":"pollResponse","pollResponse":` + `[{"type":"brokerSelected","brokerSelected":{"brokerId":"a broker"}},` + `{"authModeSelected":{"authModeId":"auth mode"}}]}`, wantErrMsg: "poll response data member 1 invalid: missing event type", }, - "Error pollResponse packet with unsupported event type": { + "Error_pollResponse_packet_with_unsupported_event_type": { JSON: `{"type":"pollResponse","pollResponse":` + `[{"type":"brokerSelected","brokerSelected":{"brokerId":"a broker"}},` + `{"type":"invalidEvent"}]}`, wantErrMsg: "invalid value for enum field type", }, - "Error pollResponse packet with unexpected data": { + "Error_pollResponse_packet_with_unexpected_data": { JSON: `{"type":"pollResponse","pollResponse":` + `[{"type":"brokerSelected","brokerSelected":{"brokerId":"a broker"}},` + `{"type":"authModeSelected","authModeSelected":{"authModeId":"auth mode"}}],` + diff --git a/pam/internal/pam_test/module-transaction-dummy_test.go b/pam/internal/pam_test/module-transaction-dummy_test.go index ca22a9486..6b7a42af1 100644 --- a/pam/internal/pam_test/module-transaction-dummy_test.go +++ b/pam/internal/pam_test/module-transaction-dummy_test.go @@ -31,27 +31,27 @@ func TestSetGetItem(t *testing.T) { wantGetError error wantSetError error }{ - "Set user": { + "Set_user": { item: pam.User, value: ptrValue("an user"), }, - "Returns empty when getting an unset user": { + "Returns_empty_when_getting_an_unset_user": { item: pam.User, wantValue: ptrValue(""), }, - "Setting and getting an user": { + "Setting_and_getting_an_user": { item: pam.User, value: ptrValue("the-user"), wantValue: ptrValue("the-user"), }, // Error cases - "Error when setting invalid item": { + "Error_when_setting_invalid_item": { item: pam.Item(-1), value: ptrValue("some value"), wantSetError: pam.ErrBadItem, }, - "Error when getting invalid item": { + "Error_when_getting_invalid_item": { item: pam.Item(-1), wantGetError: pam.ErrBadItem, wantValue: ptrValue(""), @@ -91,32 +91,32 @@ func TestSetPutEnv(t *testing.T) { wantValue *string wantPutError error }{ - "Put var": { + "Put_var": { env: "AN_ENV", value: ptrValue("value"), }, - "Unset a not-previously set value": { + "Unset_a_not-previously_set_value": { env: "NEVER_SET_ENV", wantPutError: pam.ErrBadItem, wantValue: ptrValue(""), }, - "Unset a preset value": { + "Unset_a_preset_value": { presetValues: map[string]string{"PRESET_ENV": "hey!"}, env: "PRESET_ENV", wantValue: ptrValue(""), }, - "Changes a preset var": { + "Changes_a_preset_var": { presetValues: map[string]string{"PRESET_ENV": "hey!"}, env: "PRESET_ENV", value: ptrValue("hello!"), wantValue: ptrValue("hello!"), }, - "Get an unset env": { + "Get_an_unset_env": { skipPut: true, env: "AN_UNSET_ENV", wantValue: ptrValue(""), }, - "Gets an invalid env name": { + "Gets_an_invalid_env_name": { env: "", value: ptrValue("Invalid Value"), wantValue: ptrValue(""), @@ -124,7 +124,7 @@ func TestSetPutEnv(t *testing.T) { }, // Error cases - "Error when putting an invalid env name": { + "Error_when_putting_an_invalid_env_name": { env: "", value: ptrValue("Invalid Value"), wantPutError: pam.ErrBadItem, @@ -197,13 +197,13 @@ func TestSetGetData(t *testing.T) { wantSetError error wantGetError error }{ - "Sets and gets data": { + "Sets_and_gets_data": { presetData: map[string]any{"some-data": []any{"hey! That's", true}}, key: "data", data: []any{"hey! That's", true}, wantData: []any{"hey! That's", true}, }, - "Set replaces data": { + "Set_replaces_data": { presetData: map[string]any{"some-data": []any{"hey! That's", true}}, key: "some-data", data: ModuleTransactionDummy{ @@ -217,14 +217,14 @@ func TestSetGetData(t *testing.T) { }, // This is weird, but it's to mimic actual PAM behavior: // See: https://github.com/linux-pam/linux-pam/pull/780 - "Nil is returned when getting data that has been removed": { + "Nil_is_returned_when_getting_data_that_has_been_removed": { presetData: map[string]any{"some-data": []any{"hey! That's", true}}, key: "some-data", data: nil, }, // Error cases - "Error when getting data that has never been set": { + "Error_when_getting_data_that_has_never_been_set": { skipSet: true, key: "not set", wantGetError: pam.ErrNoModuleData, @@ -269,18 +269,18 @@ func TestGetUser(t *testing.T) { want string wantError error }{ - "Getting a previously set user does not require conversation handler": { + "Getting_a_previously_set_user_does_not_require_conversation_handler": { presetUser: "an-user", want: "an-user", }, - "Getting a previously set user does not use conversation handler": { + "Getting_a_previously_set_user_does_not_use_conversation_handler": { presetUser: "an-user", want: "an-user", convHandler: pam.ConversationFunc(func(s pam.Style, msg string) (string, error) { return "another-user", pam.ErrConv }), }, - "Getting the user uses conversation handler if none was set": { + "Getting_the_user_uses_conversation_handler_if_none_was_set": { want: "provided-user", convHandler: pam.ConversationFunc( func(s pam.Style, msg string) (string, error) { @@ -296,7 +296,7 @@ func TestGetUser(t *testing.T) { }, // Error cases - "Error when no conversation is set": { + "Error_when_no_conversation_is_set": { want: "", wantError: pam.ErrConv, }, @@ -337,12 +337,12 @@ func TestStartStringConv(t *testing.T) { want string wantError error }{ - "Messages with error style are handled by conversation": { + "Messages_with_error_style_are_handled_by_conversation": { prompt: "This is an error!", convStyle: pam.ErrorMsg, want: "I'm handling it fine though", }, - "Conversation prompt can be formatted": { + "Conversation_prompt_can_be_formatted": { promptFormat: "Sending some %s, right? %v", promptFormatArgs: []interface{}{"info", true}, convStyle: pam.TextInfo, @@ -350,17 +350,17 @@ func TestStartStringConv(t *testing.T) { }, // Error cases - "Error if no conversation handler is set": { + "Error_if_no_conversation_handler_is_set": { convHandler: ptrValue(pam.ConversationFunc(nil)), wantError: pam.ErrConv, }, - "Error if the conversation handler fails": { + "Error_if_the_conversation_handler_fails": { prompt: "Tell me your secret!", convStyle: pam.PromptEchoOff, convError: pam.ErrBuf, wantError: pam.ErrBuf, }, - "Error when conversation uses binary content style": { + "Error_when_conversation_uses_binary_content_style": { prompt: "I am a binary content\xff!", convStyle: pam.BinaryPrompt, convError: pam.ErrConv, @@ -429,24 +429,24 @@ func TestStartBinaryConv(t *testing.T) { want []byte wantError error }{ - "Simple binary conversation": { + "Simple_binary_conversation": { request: []byte{0x01, 0x02, 0x03}, want: []byte{0x00, 0x01, 0x02, 0x03, 0x4}, }, // Error cases - "Error if no conversation handler is set": { + "Error_if_no_conversation_handler_is_set": { convHandler: ptrValue(pam.ConversationHandler(nil)), wantError: pam.ErrConv, }, - "Error if no binary conversation handler is set": { + "Error_if_no_binary_conversation_handler_is_set": { convHandler: ptrValue(pam.ConversationHandler(pam.ConversationFunc( func(s pam.Style, msg string) (string, error) { return "", nil }))), wantError: pam.ErrConv, }, - "Error if the conversation handler fails": { + "Error_if_the_conversation_handler_fails": { request: []byte{0x03, 0x02, 0x01}, convError: pam.ErrBuf, wantError: pam.ErrBuf, @@ -509,37 +509,37 @@ func TestStartBinaryPointerConv(t *testing.T) { want []byte wantError error }{ - "With nil argument": { + "With_nil_argument": { request: nil, want: nil, }, - "With empty argument": { + "With_empty_argument": { request: []byte{}, want: []byte{}, }, - "With simple argument": { + "With_simple_argument": { request: []byte{0x01, 0x02, 0x03}, want: []byte{0x00, 0x01, 0x02, 0x03, 0x4}, }, // Error cases - "Error if no conversation handler is set": { + "Error_if_no_conversation_handler_is_set": { convHandler: ptrValue(pam.ConversationHandler(nil)), wantError: pam.ErrConv, }, - "Error if no binary conversation handler is set": { + "Error_if_no_binary_conversation_handler_is_set": { convHandler: ptrValue(pam.ConversationHandler(pam.ConversationFunc( func(s pam.Style, msg string) (string, error) { return "", nil }))), wantError: pam.ErrConv, }, - "Error if the conversation handler fails": { + "Error_if_the_conversation_handler_fails": { request: []byte{0xde, 0xad, 0xbe, 0xef, 0xf}, convError: pam.ErrBuf, wantError: pam.ErrBuf, }, - "Error if no conversation handler is set handles allocated data": { + "Error_if_no_conversation_handler_is_set_handles_allocated_data": { convError: pam.ErrSystem, want: []byte{0xde, 0xad, 0xbe, 0xef, 0xf}, wantError: pam.ErrSystem, @@ -655,7 +655,7 @@ func TestStartConvMulti(t *testing.T) { wantConvCalls *int wantError error }{ - "Can address multiple string requests": { + "Can_address_multiple_string_requests": { requests: []pam.ConvRequest{ pam.NewStringConvRequest(pam.PromptEchoOff, "give some PromptEchoOff"), pam.NewStringConvRequest(pam.PromptEchoOn, "give some PromptEchoOn"), @@ -669,7 +669,7 @@ func TestStartConvMulti(t *testing.T) { StringResponseDummy{pam.TextInfo, "answer to TextInfo"}, }, }, - "Can address multiple binary requests": { + "Can_address_multiple_binary_requests": { requests: []pam.ConvRequest{ NewBinaryRequestDummy(nil), NewBinaryRequestDummy(pam.BinaryPointer(&[]byte{})), @@ -683,7 +683,7 @@ func TestStartConvMulti(t *testing.T) { &BinaryResponseDummy{pam.BinaryPointer(&[]byte{0xAF, 0x00, 0xBA, 0xAC})}, }, }, - "Can address multiple mixed binary and string requests ": { + "Can_address_multiple_mixed_binary_and_string_requests": { requests: []pam.ConvRequest{ NewBinaryRequestDummy(nil), pam.NewStringConvRequest(pam.PromptEchoOff, "PromptEchoOff"), @@ -707,10 +707,10 @@ func TestStartConvMulti(t *testing.T) { }, // Error cases - "Error if no request is provided": { + "Error_if_no_request_is_provided": { wantError: pam.ErrConv, }, - "Error if one of the multiple request fails": { + "Error_if_one_of_the_multiple_request_fails": { requests: []pam.ConvRequest{ NewBinaryRequestDummy(nil), pam.NewStringConvRequest(pam.PromptEchoOff, "PromptEchoOff"), diff --git a/pam/internal/pam_test/pam-client-dummy_test.go b/pam/internal/pam_test/pam-client-dummy_test.go index d0eb1fed0..fa58f2507 100644 --- a/pam/internal/pam_test/pam-client-dummy_test.go +++ b/pam/internal/pam_test/pam-client-dummy_test.go @@ -31,15 +31,15 @@ func TestAvailableBrokers(t *testing.T) { wantRet *authd.ABResponse wantError error }{ - "With empty options": { + "With_empty_options": { client: NewDummyClient(nil), wantRet: &authd.ABResponse{}, }, - "With Error return value": { + "With_Error_return_value": { client: NewDummyClient(nil, WithAvailableBrokers(nil, errTest)), wantError: errTest, }, - "With defined return value": { + "With_defined_return_value": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{ { Id: "testBroker", @@ -79,25 +79,25 @@ func TestGetPreviousBroker(t *testing.T) { wantRet *authd.GPBResponse wantError error }{ - "With empty options": { + "With_empty_options": { client: NewDummyClient(nil), wantRet: &authd.GPBResponse{}, }, - "With Error return value": { + "With_Error_return_value": { client: NewDummyClient(nil, WithGetPreviousBrokerReturn("", errTest)), wantError: errTest, }, - "With defined return value": { + "With_defined_return_value": { client: NewDummyClient(nil, WithGetPreviousBrokerReturn("my-previous-broker", nil)), wantRet: &authd.GPBResponse{ PreviousBroker: "my-previous-broker", }, }, - "With defined empty return value": { + "With_defined_empty_return_value": { client: NewDummyClient(nil, WithGetPreviousBrokerReturn("", nil)), wantRet: &authd.GPBResponse{}, }, - "With predefined default for user empty return value": { + "With_predefined_default_for_user_empty_return_value": { client: NewDummyClient(nil, WithPreviousBrokerForUser("user0", "broker0"), WithPreviousBrokerForUser("user1", "broker1"), @@ -107,7 +107,7 @@ func TestGetPreviousBroker(t *testing.T) { }, // Error cases - "Error with missing user": { + "Error_with_missing_user": { client: NewDummyClient(nil, WithGetPreviousBrokerReturn("", nil)), args: &authd.GPBRequest{}, wantError: errors.New("no username provided"), @@ -140,11 +140,11 @@ func TestSelectBroker(t *testing.T) { wantRet *authd.SBResponse wantError error }{ - "With Error return value": { + "With_Error_return_value": { client: NewDummyClient(nil, WithSelectBrokerReturn(nil, errTest)), wantError: errTest, }, - "With valid args and generated return value": { + "With_valid_args_and_generated_return_value": { client: NewDummyClient(nil, WithSelectBrokerReturn(nil, nil), WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{ @@ -156,7 +156,7 @@ func TestSelectBroker(t *testing.T) { args: &authd.SBRequest{BrokerId: "test-broker"}, wantGeneratedSessionID: true, }, - "With valid args and empty return value": { + "With_valid_args_and_empty_return_value": { client: NewDummyClient(nil, WithSelectBrokerReturn(&authd.SBResponse{}, nil), WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{ @@ -169,7 +169,7 @@ func TestSelectBroker(t *testing.T) { wantRet: &authd.SBResponse{}, wantGeneratedSessionID: true, }, - "With valid args and empty return value with ignored ID generation": { + "With_valid_args_and_empty_return_value_with_ignored_ID_generation": { client: NewDummyClient(nil, WithIgnoreSessionIDGeneration(), WithSelectBrokerReturn(&authd.SBResponse{}, nil), @@ -182,7 +182,7 @@ func TestSelectBroker(t *testing.T) { args: &authd.SBRequest{BrokerId: "test-broker"}, wantRet: &authd.SBResponse{}, }, - "With valid args and defined return value": { + "With_valid_args_and_defined_return_value": { client: NewDummyClient(nil, WithSelectBrokerReturn(&authd.SBResponse{ SessionId: "session-id", @@ -200,7 +200,7 @@ func TestSelectBroker(t *testing.T) { EncryptionKey: "super-secret-encryption-key", }, }, - "With private key and valid args and empty return value": { + "With_private_key_and_valid_args_and_empty_return_value": { client: NewDummyClient(privateKey, WithSelectBrokerReturn(&authd.SBResponse{}, nil), WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{ @@ -215,7 +215,7 @@ func TestSelectBroker(t *testing.T) { }, wantGeneratedSessionID: true, }, - "With private key and valid args, empty return value ignoring session ID generation": { + "With_private_key_and_valid_args,_empty_return_value_ignoring_session_ID_generation": { client: NewDummyClient(privateKey, WithIgnoreSessionIDGeneration(), WithSelectBrokerReturn(&authd.SBResponse{}, nil), @@ -230,7 +230,7 @@ func TestSelectBroker(t *testing.T) { EncryptionKey: wantEncryptionKey, }, }, - "With private key and valid args and defined return value": { + "With_private_key_and_valid_args_and_defined_return_value": { client: NewDummyClient(privateKey, WithSelectBrokerReturn(&authd.SBResponse{ SessionId: "session-id", @@ -252,7 +252,7 @@ func TestSelectBroker(t *testing.T) { EncryptionKey: "super-secret-encryption-key", }, }, - "With private key and valid args and defined return value without encryption key": { + "With_private_key_and_valid_args_and_defined_return_value_without_encryption_key": { client: NewDummyClient(privateKey, WithSelectBrokerReturn(&authd.SBResponse{ SessionId: "session-id", @@ -273,7 +273,7 @@ func TestSelectBroker(t *testing.T) { EncryptionKey: wantEncryptionKey, }, }, - "Starting a session for same user is fine": { + "Starting_a_session_for_same_user_is_fine": { client: NewDummyClient(nil, WithSelectBrokerReturn(nil, nil), WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{ @@ -290,7 +290,7 @@ func TestSelectBroker(t *testing.T) { wantGeneratedSessionID: true, wantRet: &authd.SBResponse{}, }, - "Starting a session for another user is fine when ignoring ID checks": { + "Starting_a_session_for_another_user_is_fine_when_ignoring_ID_checks": { client: NewDummyClient(nil, WithIgnoreSessionIDChecks(), WithIgnoreSessionIDGeneration(), @@ -310,21 +310,21 @@ func TestSelectBroker(t *testing.T) { }, // Error cases - "Error with nil args and empty options": { + "Error_with_nil_args_and_empty_options": { client: NewDummyClient(nil), wantError: errors.New("no input values provided"), }, - "Error with empty args empty options": { + "Error_with_empty_args_empty_options": { client: NewDummyClient(nil), args: &authd.SBRequest{}, wantError: errors.New("no broker ID provided"), }, - "Error on unknown broker id": { + "Error_on_unknown_broker_id": { client: NewDummyClient(nil, WithSelectBrokerReturn(nil, nil)), args: &authd.SBRequest{BrokerId: "some-broker"}, wantError: fmt.Errorf(`broker "some-broker" not found`), }, - "Error on starting a session again": { + "Error_on_starting_a_session_again": { client: NewDummyClient(nil, WithSelectBrokerReturn(nil, nil), WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{ @@ -340,7 +340,7 @@ func TestSelectBroker(t *testing.T) { reselectAgainUser: "another-user", wantGeneratedSessionID: true, }, - "Error on broker fetching failed": { + "Error_on_broker_fetching_failed": { client: NewDummyClient(nil, WithSelectBrokerReturn(nil, nil), WithAvailableBrokers(nil, errTest)), @@ -420,11 +420,11 @@ func TestGetAuthenticationModes(t *testing.T) { wantRet *authd.GAMResponse wantError error }{ - "With Error return value": { + "With_Error_return_value": { client: NewDummyClient(nil, WithGetAuthenticationModesReturn(nil, errTest)), wantError: errTest, }, - "With empty return value": { + "With_empty_return_value": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -436,7 +436,7 @@ func TestGetAuthenticationModes(t *testing.T) { args: &authd.GAMRequest{SessionId: "started-session-id"}, wantRet: &authd.GAMResponse{AuthenticationModes: []*authd.GAMResponse_AuthenticationMode{}}, }, - "With all modes return value": { + "With_all_modes_return_value": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -468,7 +468,7 @@ func TestGetAuthenticationModes(t *testing.T) { }, }, }, - "With modes returned from values": { + "With_modes_returned_from_values": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -492,23 +492,23 @@ func TestGetAuthenticationModes(t *testing.T) { }, }, }, - "With no session ID arg when enabled": { + "With_no_session_ID_arg_when_enabled": { client: NewDummyClient(nil, WithIgnoreSessionIDChecks()), args: &authd.GAMRequest{}, wantRet: &authd.GAMResponse{AuthenticationModes: []*authd.GAMResponse_AuthenticationMode{}}, }, // Error cases - "Error with nil args and empty options": { + "Error_with_nil_args_and_empty_options": { client: NewDummyClient(nil), wantError: errors.New("no input values provided"), }, - "Error with no session ID arg": { + "Error_with_no_session_ID_arg": { client: NewDummyClient(nil), args: &authd.GAMRequest{}, wantError: errors.New("no session ID provided"), }, - "Error with not-matching session ID": { + "Error_with_not-matching_session_ID": { client: NewDummyClient(nil), args: &authd.GAMRequest{SessionId: "session-id"}, skipBrokerSelection: true, @@ -547,11 +547,11 @@ func TestSelectAuthenticationModes(t *testing.T) { wantRet *authd.SAMResponse wantError error }{ - "With Error return value": { + "With_Error_return_value": { client: NewDummyClient(nil, WithSelectAuthenticationModeReturn(nil, errTest)), wantError: errTest, }, - "With empty return value": { + "With_empty_return_value": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -563,7 +563,7 @@ func TestSelectAuthenticationModes(t *testing.T) { args: &authd.SAMRequest{SessionId: "started-session-id"}, wantRet: &authd.SAMResponse{UiLayoutInfo: &authd.UILayout{}}, }, - "With all modes return value": { + "With_all_modes_return_value": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -583,22 +583,22 @@ func TestSelectAuthenticationModes(t *testing.T) { }, // Error cases - "Error with nil args and empty options": { + "Error_with_nil_args_and_empty_options": { client: NewDummyClient(nil), wantError: errors.New("no input values provided"), }, - "Error with no session ID arg": { + "Error_with_no_session_ID_arg": { client: NewDummyClient(nil), args: &authd.SAMRequest{}, wantError: errors.New("no session ID provided"), }, - "Error with not-matching session ID": { + "Error_with_not-matching_session_ID": { client: NewDummyClient(nil), args: &authd.SAMRequest{SessionId: "session-id"}, skipBrokerSelection: true, wantError: errors.New(`impossible to select authentication mode, session ID "session-id" not found`), }, - "Error with no authentication mode ID": { + "Error_with_no_authentication_mode_ID": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -610,7 +610,7 @@ func TestSelectAuthenticationModes(t *testing.T) { args: &authd.SAMRequest{SessionId: "started-session-id"}, wantError: errors.New("no authentication mode ID provided"), }, - "Error unknown authentication mode ID": { + "Error_unknown_authentication_mode_ID": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -653,11 +653,11 @@ func TestIsAuthenticated(t *testing.T) { wantRet *authd.IAResponse wantError error }{ - "With Error return value": { + "With_Error_return_value": { client: NewDummyClient(nil, WithIsAuthenticatedReturn(nil, errTest)), wantError: errTest, }, - "With empty return value": { + "With_empty_return_value": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -669,7 +669,7 @@ func TestIsAuthenticated(t *testing.T) { args: &authd.IARequest{SessionId: "started-session-id"}, wantRet: &authd.IAResponse{}, }, - "With retry return value": { + "With_retry_return_value": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -687,7 +687,7 @@ func TestIsAuthenticated(t *testing.T) { Msg: "Try again", }, }, - "Invalid challenge": { + "Invalid_challenge": { client: NewDummyClient(privateKey, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -708,7 +708,7 @@ func TestIsAuthenticated(t *testing.T) { Access: auth.Denied, }, }, - "Invalid challenge with message": { + "Invalid_challenge_with_message": { client: NewDummyClient(privateKey, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -731,7 +731,7 @@ func TestIsAuthenticated(t *testing.T) { Msg: `{"message": "You're out!"}`, }, }, - "Retry challenge with message": { + "Retry_challenge_with_message": { client: NewDummyClient(privateKey, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -755,7 +755,7 @@ func TestIsAuthenticated(t *testing.T) { Msg: `{"message": "try again!"}`, }, }, - "Valid challenge": { + "Valid_challenge": { client: NewDummyClient(privateKey, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -776,7 +776,7 @@ func TestIsAuthenticated(t *testing.T) { Access: auth.Granted, }, }, - "Valid challenge with message": { + "Valid_challenge_with_message": { client: NewDummyClient(privateKey, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -799,7 +799,7 @@ func TestIsAuthenticated(t *testing.T) { Msg: `{"message": "try again!"}`, }, }, - "Wait with message": { + "Wait_with_message": { client: NewDummyClient(privateKey, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -820,7 +820,7 @@ func TestIsAuthenticated(t *testing.T) { Msg: `{"message": "Wait done!"}`, }, }, - "Skip with message": { + "Skip_with_message": { client: NewDummyClient(privateKey, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -842,22 +842,22 @@ func TestIsAuthenticated(t *testing.T) { }, // Error cases - "Error with nil args and empty options": { + "Error_with_nil_args_and_empty_options": { client: NewDummyClient(nil), wantError: errors.New("no input values provided"), }, - "Error with no session ID arg": { + "Error_with_no_session_ID_arg": { client: NewDummyClient(nil), args: &authd.IARequest{}, wantError: errors.New("no session ID provided"), }, - "Error with not-matching session ID": { + "Error_with_not-matching_session_ID": { client: NewDummyClient(nil), args: &authd.IARequest{SessionId: "session-id"}, skipBrokerSelection: true, wantError: errors.New(`impossible to authenticate, session ID "session-id" not found`), }, - "Error with no authentication data": { + "Error_with_no_authentication_data": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -868,7 +868,7 @@ func TestIsAuthenticated(t *testing.T) { args: &authd.IARequest{SessionId: "started-session-id"}, wantError: errors.New("no authentication data provided"), }, - "Error with invalid authentication data": { + "Error_with_invalid_authentication_data": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -883,7 +883,7 @@ func TestIsAuthenticated(t *testing.T) { }, wantError: errors.New("no authentication data provided"), }, - "Error missing wanted challenge": { + "Error_missing_wanted_challenge": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -899,7 +899,7 @@ func TestIsAuthenticated(t *testing.T) { }, wantError: errors.New("no wanted challenge provided"), }, - "Error missing wanted wait": { + "Error_missing_wanted_wait": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -915,7 +915,7 @@ func TestIsAuthenticated(t *testing.T) { }, wantError: errors.New("no wanted wait provided"), }, - "Error missing wanted skip": { + "Error_missing_wanted_skip": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -931,7 +931,7 @@ func TestIsAuthenticated(t *testing.T) { }, wantError: errors.New("no wanted skip requested"), }, - "Error empty challenge": { + "Error_empty_challenge": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -948,7 +948,7 @@ func TestIsAuthenticated(t *testing.T) { }, wantError: errors.New("no challenge provided"), }, - "Error decoding challenge": { + "Error_decoding_challenge": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -967,7 +967,7 @@ func TestIsAuthenticated(t *testing.T) { }, wantError: base64.CorruptInputError(7), }, - "Error decrypting challenge per missing private key": { + "Error_decrypting_challenge_per_missing_private_key": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -986,7 +986,7 @@ func TestIsAuthenticated(t *testing.T) { }, wantError: errors.New("no private key defined"), }, - "Error decrypting invalid challenge": { + "Error_decrypting_invalid_challenge": { client: NewDummyClient(privateKey, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -1043,11 +1043,11 @@ func TestEndSession(t *testing.T) { wantError error }{ - "With Error return value": { + "With_Error_return_value": { client: NewDummyClient(nil, WithEndSessionReturn(errTest)), wantError: errTest, }, - "With valid return value": { + "With_valid_return_value": { client: NewDummyClient(nil, WithAvailableBrokers([]*authd.ABResponse_BrokerInfo{{ Id: "test-broker", @@ -1062,16 +1062,16 @@ func TestEndSession(t *testing.T) { }, // Error cases - "Error with nil args and empty options": { + "Error_with_nil_args_and_empty_options": { client: NewDummyClient(nil), wantError: errors.New("no input values provided"), }, - "Error with empty args empty options": { + "Error_with_empty_args_empty_options": { client: NewDummyClient(nil), args: &authd.ESRequest{}, wantError: errors.New("no session ID provided"), }, - "Error with not-matching session ID": { + "Error_with_not-matching_session_ID": { client: NewDummyClient(nil), args: &authd.ESRequest{SessionId: "a-session-id"}, wantError: errors.New(`impossible to end session "a-session-id", not found`), @@ -1117,15 +1117,15 @@ func TestSetDefaultBrokerForUser(t *testing.T) { wantError error }{ - "With empty options": { + "With_empty_options": { client: NewDummyClient(nil), wantError: errors.New("no input values provided"), }, - "With Error return value": { + "With_Error_return_value": { client: NewDummyClient(nil, WithSetDefaultBrokerReturn(errTest)), wantError: errTest, }, - "With valid arguments": { + "With_valid_arguments": { client: NewDummyClient(nil, WithSetDefaultBrokerReturn(nil)), args: &authd.SDBFURequest{ BrokerId: "broker-id", @@ -1134,12 +1134,12 @@ func TestSetDefaultBrokerForUser(t *testing.T) { }, // Error cases - "Error if no user name is provided": { + "Error_if_no_user_name_is_provided": { client: NewDummyClient(nil), args: &authd.SDBFURequest{BrokerId: "broker-id"}, wantError: errors.New("no valid username provided"), }, - "Error if no broker ID is provided": { + "Error_if_no_broker_ID_is_provided": { client: NewDummyClient(nil), args: &authd.SDBFURequest{Username: "username"}, wantError: errors.New("no valid broker ID provided"),