def test_user_modify_includes_extra_names_when_given_names(mocker):
    test_utils.mock_options_passed_to_ipa(
        mocker,
        ['user', 'modify', 'barney', '--first', 'Barney', '--last', 'Rubble'],
        [('user-mod', [[
            'barney', '--cn', 'Barney Rubble', '--displayname',
            'Barney Rubble', '--first', 'Barney', '--last', 'Rubble'
        ]])])
def test_user_modify_without_modifications_calls_ipa_correctly(mocker):
    test_utils.mock_ipa_find_output(mocker)
    test_utils.mock_options_passed_to_ipa(
        mocker, ['user', 'modify'], [('user-mod', [[
            'walterwhite', '--cn', 'walterwhite_first walterwhite_last',
            '--displayname', 'walterwhite_first walterwhite_last', '--email',
            'walterwhite_email', '--first', 'walterwhite_first', '--last',
            'walterwhite_last'
        ]])], 'walterwhite\n\n\n\n\n')
def test_user_create_does_not_pass_random_when_given_no_password(mocker):
    test_utils.mock_ipa_find_output(mocker)
    test_utils.mock_options_passed_to_ipa(mocker, [
        'user', 'create', 'barney', '--first', 'Barney', '--last', 'Rubble',
        '--no-password'
    ], [('user-add', [[
        'barney', '--first', 'Barney', '--gidnumber', 'clusterusers_gid',
        '--last', 'Rubble'
    ]])])
def test_user_modify_passes_random_password_when_given_remove_password(
        mocker, monkeypatch):
    mock_password = '******'
    monkeypatch.setattr(appliance_cli.utils, 'secure_random_string',
                        lambda: mock_password)

    test_utils.mock_options_passed_to_ipa(
        mocker, ['user', 'modify', 'barney', '--remove-password'],
        [('user-mod', [['barney', '--password', mock_password]])])
def test_user_create_passes_sshpubkey_when_given_key(mocker):
    test_utils.mock_ipa_find_output(mocker)
    test_utils.mock_options_passed_to_ipa(mocker, [
        'user', 'create', 'barney', '--first', 'Barney', '--last', 'Rubble',
        '--key', 'ssh-rsa somekey key_name'
    ], [('user-add', [[
        'barney', '--first', 'Barney', '--gidnumber', 'clusterusers_gid',
        '--last', 'Rubble', '--random', '--sshpubkey',
        'ssh-rsa somekey key_name'
    ]])])
def test_user_create_includes_random_by_default(mocker):
    test_utils.mock_ipa_find_output(mocker)
    test_utils.mock_options_passed_to_ipa(
        mocker,
        ['user', 'create', 'barney', '--first', 'Barney', '--last', 'Rubble'],
        [('user-add', [[
            'barney', '--first', 'Barney', '--gidnumber', 'clusterusers_gid',
            '--last', 'Rubble', '--random'
        ]])],
    )
def test_user_create_without_uid_calls_ipa_correctly(mocker):
    test_utils.mock_ipa_find_output(mocker)
    test_utils.mock_options_passed_to_ipa(
        mocker,
        ['user', 'create'],
        [('user-add', [[
            'walterwhite', '--email', '*****@*****.**', '--first',
            'Walter', '--gidnumber', 'clusterusers_gid', '--last', 'White',
            '--random'
        ]])],
        'walterwhite\nWalter\nWhite\[email protected]\nNo\n',
    )
def test_user_modify_with_modifications_calls_ipa_correctly(mocker):
    test_utils.mock_ipa_find_output(mocker)
    test_utils.mock_options_passed_to_ipa(
        mocker,
        ['user', 'modify'],
        [('user-mod', [[
            'walterwhite',
            '--cn',
            'Walt Jackson',
            '--displayname',
            'Walt Jackson',
            '--email',
            '*****@*****.**',
            '--first',
            'Walt',
            '--last',
            'Jackson',
        ]])],
        'walterwhite\nWalt\nJackson\[email protected]\nNo\n',
    )
def test_user_modify_passes_random_when_given_new_password(mocker):
    test_utils.mock_options_passed_to_ipa(
        mocker, ['user', 'modify', 'barney', '--new-password'],
        [('user-mod', [['barney', '--random']])])
def test_user_modify_includes_nothing_extra_by_default(mocker):
    test_utils.mock_options_passed_to_ipa(mocker, ['user', 'modify', 'barney'],
                                          [('user-mod', [['barney']])])
def test_user_modify_passes_empty_sshpubkey_when_given_remove_key(mocker):
    test_utils.mock_options_passed_to_ipa(
        mocker, ['user', 'modify', 'barney', '--remove-key'],
        [('user-mod', [['barney', '--sshpubkey', '']])])
def test_user_modify_passes_sshpubkey_when_given_key(mocker):
    test_utils.mock_options_passed_to_ipa(mocker, [
        'user', 'modify', 'barney', '--key', 'ssh-rsa somekey key_name'
    ], [('user-mod', [['barney', '--sshpubkey', 'ssh-rsa somekey key_name']])])
Example #13
0
def test_group_modify_without_modifications_calls_ipa_correctly(mocker):
    test_utils.mock_ipa_find_output(mocker)
    test_utils.mock_options_passed_to_ipa(
        mocker, ['group', 'modify'],
        [('group-mod', [['clustertonkers', '--desc', 'clustertonkers_desc']])],
        'clustertonkers\n\n')
Example #14
0
def test_group_modify_with_modifications_calls_ipa_correctly(mocker):
    test_utils.mock_ipa_find_output(mocker)
    test_utils.mock_options_passed_to_ipa(
        mocker, ['group', 'modify'], [('group-mod', [[
            'clustertonkers', '--desc', 'this is a more relevant description'
        ]])], 'clustertonkers\nthis is a more relevant description\n')
Example #15
0
def test_group_create_without_gid_calls_ipa_correctly(mocker):
    test_utils.mock_options_passed_to_ipa(
        mocker, ['group', 'create'],
        [('group-add',
          [['clustertonkers', '--desc', 'very useful description']])],
        'clustertonkers\nvery useful description\nNo\n')