Example #1
0
def test_cloud_key_store_get_key_name_pattern():
    for i in range(100):
        CloudKeyStore._sample_keys = None
        # repeat for better reproducibility

        driver = KeyPairSupportedDummyNodeDriver('')
        keystore = CloudKeyStore(driver)
        identity = Identity(DummyTeam, 'abcd')
        pattern = keystore._get_key_name_pattern(identity)
        print('Cached CloudKeyStore._sample_keys:', CloudKeyStore._sample_keys)
        print('Cached CloudKeyStore._sample_keys (as names):',
              tuple(keystore._get_key_name(identity, k)
                    for k in CloudKeyStore._sample_keys))
        print('Generated pattern:', pattern.pattern)

        def random_fp():
            return ':'.join(
                map('{:02x}'.format, hashlib.md5(os.urandom(100)).digest())
            )
        actual = {
            'tests.server_test.DummyTeam abcd ' + random_fp()
            for _ in range(5)
        }
        result = filter(pattern.match, actual | {
            'tests.server_test.DummyTeam defg ' + random_fp(),
            'tests.server_test.OtherTeam abcd ' + random_fp(),
            'tests.server_test.DummyTeam abcd ',
            'junk'
        })
        result = frozenset(result)
        assert result == actual
Example #2
0
def test_cloud_key_store_get_key_name_pattern():
    for i in range(100):
        CloudKeyStore._sample_keys = None
        # repeat for better reproducibility

        driver = KeyPairSupportedDummyNodeDriver('')
        keystore = CloudKeyStore(driver)
        identity = Identity(DummyTeam, 'abcd')
        pattern = keystore._get_key_name_pattern(identity)
        print('Cached CloudKeyStore._sample_keys:', CloudKeyStore._sample_keys)
        print(
            'Cached CloudKeyStore._sample_keys (as names):',
            tuple(
                keystore._get_key_name(identity, k)
                for k in CloudKeyStore._sample_keys))
        print('Generated pattern:', pattern.pattern)

        def random_fp():
            return ':'.join(
                map('{:02x}'.format,
                    hashlib.md5(os.urandom(100)).digest()))

        actual = {
            'tests.server_test.DummyTeam abcd ' + random_fp()
            for _ in range(5)
        }
        result = filter(
            pattern.match, actual | {
                'tests.server_test.DummyTeam defg ' + random_fp(),
                'tests.server_test.OtherTeam abcd ' + random_fp(),
                'tests.server_test.DummyTeam abcd ', 'junk'
            })
        result = frozenset(result)
        assert result == actual
Example #3
0
def test_cloud_key_store():
    driver = KeyPairSupportedDummyNodeDriver('')
    keystore = CloudKeyStore(driver)
    identity = Identity(DummyTeam, 'abcd')
    assert_keystore_compliance(keystore, identity)
    identity2 = Identity(DummyTeam, 'efg')
    assert_keystore_compliance(keystore, identity2)
Example #4
0
def test_cloud_key_store_get_key_name_pattern():
    driver = KeyPairSupportedDummyNodeDriver("")
    keystore = CloudKeyStore(driver)
    identity = Identity(DummyTeam, "abcd")
    pattern = keystore._get_key_name_pattern(identity)
    random_fp = lambda: ":".join(map("{:02x}".format, hashlib.md5(os.urandom(100)).digest()))
    actual = {"tests.server_test.DummyTeam abcd " + random_fp() for _ in range(5)}
    result = filter(
        pattern.match,
        actual
        | {
            "tests.server_test.DummyTeam defg " + random_fp(),
            "tests.server_test.OtherTeam abcd " + random_fp(),
            "tests.server_test.DummyTeam abcd ",
            "junk",
        },
    )
    assert frozenset(result) == actual
Example #5
0
def test_cloud_key_store_get_key_name_pattern():
    driver = KeyPairSupportedDummyNodeDriver('')
    keystore = CloudKeyStore(driver)
    identity = Identity(DummyTeam, 'abcd')
    pattern = keystore._get_key_name_pattern(identity)
    random_fp = lambda: ':'.join(
        map('{:02x}'.format,
            hashlib.md5(os.urandom(100)).digest()))
    actual = {
        'tests.server_test.DummyTeam abcd ' + random_fp()
        for _ in range(5)
    }
    result = filter(
        pattern.match, actual | {
            'tests.server_test.DummyTeam defg ' + random_fp(),
            'tests.server_test.OtherTeam abcd ' + random_fp(),
            'tests.server_test.DummyTeam abcd ', 'junk'
        })
    assert frozenset(result) == actual
Example #6
0
def test_cloud_key_store_get_key_name_pattern():
    driver = KeyPairSupportedDummyNodeDriver('')
    keystore = CloudKeyStore(driver)
    identity = Identity(DummyTeam, 'abcd')
    pattern = keystore._get_key_name_pattern(identity)

    def random_fp():
        return ':'.join(
            map('{:02x}'.format, hashlib.md5(os.urandom(100)).digest())
        )
    actual = {
        'tests.server_test.DummyTeam abcd ' + random_fp()
        for _ in range(5)
    }
    result = filter(pattern.match, actual | {
        'tests.server_test.DummyTeam defg ' + random_fp(),
        'tests.server_test.OtherTeam abcd ' + random_fp(),
        'tests.server_test.DummyTeam abcd ',
        'junk'
    })
    assert frozenset(result) == actual