示例#1
0
def test_read_accounts_csv_disableDetective():
	args = disableDetective.setup_command_line(['--master_account', '555555555555', '--assume_role', 'detectiveAdmin', '--disabled_regions', 'us-east-1,us-east-2,us-west-2,ap-northeast-1,eu-west-1', '--input_file', 'accounts.csv'])

	accounts_dict = disableDetective.read_accounts_csv(args.input_file)

	assert len(accounts_dict.keys()) == 6
	assert accounts_dict == {"123456789012":"*****@*****.**", "000012345678":"*****@*****.**", "555555555555":"*****@*****.**", "111111111111":"*****@*****.**", "222222222222":"*****@*****.**", "333333333333":"*****@*****.**"}
示例#2
0
def test_read_accounts_csv_disableDetective():
    # a test case where an input file is provided, although some of the lines are not correct
    args = disableDetective.setup_command_line([
        '--master_account', '555555555555', '--assume_role', 'detectiveAdmin',
        '--disabled_regions',
        'us-east-1,us-east-2,us-west-2,ap-northeast-1,eu-west-1',
        '--input_file', 'accounts.csv'
    ])

    accounts_dict = disableDetective.read_accounts_csv(args.input_file)

    assert len(accounts_dict.keys()) == 6
    assert accounts_dict == {
        "123456789012": "*****@*****.**",
        "000012345678": "*****@*****.**",
        "555555555555": "*****@*****.**",
        "111111111111": "*****@*****.**",
        "222222222222": "*****@*****.**",
        "333333333333": "*****@*****.**"
    }

    # a test case where no input file is provided
    args = disableDetective.setup_command_line([
        '--master_account', '555555555555', '--assume_role', 'detectiveAdmin',
        '--disabled_regions',
        'us-east-1,us-east-2,us-west-2,ap-northeast-1,eu-west-1',
        '--delete_graph'
    ])
    assert args.input_file == None
    accounts_dict = disableDetective.read_accounts_csv(args.input_file)
    assert accounts_dict == {}

    # a test case where an empty input file is provided, along with delete_graph. This is not an error, although clients should not run with this kind of input
    args = disableDetective.setup_command_line([
        '--master_account', '555555555555', '--assume_role', 'detectiveAdmin',
        '--disabled_regions',
        'us-east-1,us-east-2,us-west-2,ap-northeast-1,eu-west-1',
        '--input_file', 'accounts2.csv', '--delete_graph'
    ])
    accounts_dict = disableDetective.read_accounts_csv(args.input_file)
    assert accounts_dict == {}
    assert args.delete_graph == True
示例#3
0
def test_setup_command_line_disableDetective():
    
    args = disableDetective.setup_command_line(['--master_account', '555555555555', '--assume_role', 'detectiveAdmin', '--disabled_regions', 'us-east-1,us-east-2,us-west-2,ap-northeast-1,eu-west-1', '--input_file', 'accounts.csv'])
    assert args.master_account == '555555555555'
    assert args.assume_role == 'detectiveAdmin'
    assert args.disabled_regions == 'us-east-1,us-east-2,us-west-2,ap-northeast-1,eu-west-1'

    args = disableDetective.setup_command_line(['--master_account', '012345678901', '--assume_role', 'detectiveAdmin', '--input_file', 'accounts.csv'])
    assert args.master_account == '012345678901'
    assert args.disabled_regions == None

    args = disableDetective.setup_command_line(['--master_account', '000000000001', '--assume_role', 'detectiveAdmin', '--disabled_regions', 'us-east-1,us-east-2,us-west-2,ap-northeast-1,eu-west-1', '--input_file', 'accounts.csv'])
    assert args.master_account == '000000000001'

    # Wrong master account
    # The internal function _master_account_type() should raise argparse.ArgumentTypeError, however this exception gets supressed by argparse, and SystemExit is raised instead.
    with pytest.raises(SystemExit):
    	disableDetective.setup_command_line(['--master_account', '12345', '--assume_role', 'detectiveAdmin', '--disabled_regions', 'us-east-1,us-east-2,us-west-2,ap-northeast-1,eu-west-1', '--input_file', 'accounts.csv'])
    
    # Non existent input file
    with pytest.raises(SystemExit):
    	disableDetective.setup_command_line(['--master_account', '000000000001', '--assume_role', 'detectiveAdmin', '--disabled_regions', 'us-east-1,us-east-2,us-west-2,ap-northeast-1,eu-west-1', '--input_file', 'accounts1.csv'])