コード例 #1
0
ファイル: cloud_test.py プロジェクト: haegyung/geofront
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)
コード例 #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
コード例 #3
0
ファイル: remote_test.py プロジェクト: haegyung/geofront
def test_default_permission_policy():
    remotes = {'a': Remote('a', 'localhost'), 'b': Remote('b', 'localhost')}
    identity = Identity(DummyTeam, 'a')
    p = DefaultPermissionPolicy()
    assert p.filter(remotes, identity, {'x'}) == remotes
    for remote in remotes.values():
        assert p.permit(remote, identity, {'x'})
コード例 #4
0
def fx_github_identity(fx_github_access_token):
    global _fx_github_identity_cache
    if not _fx_github_identity_cache:
        _fx_github_identity_cache = request(fx_github_access_token,
                                            'https://api.github.com/user',
                                            'GET')
    return Identity(GitHubOrganization, _fx_github_identity_cache['login'],
                    fx_github_access_token)
コード例 #5
0
ファイル: server_test.py プロジェクト: allanice001/geofront
 def authenticate(self, state, requested_redirect_url: str,
                  wsgi_environ: dict) -> Identity:
     try:
         pair = self.states.pop()
     except IndexError:
         raise AuthenticationError()
     if pair[0] != state or pair[1] != requested_redirect_url:
         raise AuthenticationError()
     return Identity(type(self), len(self.states))
コード例 #6
0
def test_authenticate(fx_app, fx_token_store, fx_token_id):
    token_url = get_url('create_access_token', token_id=fx_token_id)
    auth_url = get_url('authenticate', token_id=fx_token_id)
    with app.test_client() as c:
        response = c.put(token_url)
        assert response.status_code == 202
        response = c.get(auth_url)
        assert response.status_code == 200
        token = fx_token_store.get(fx_token_id)
        assert isinstance(token, Token)
        assert token.identity == Identity(DummyTeam, 0)
コード例 #7
0
ファイル: server_test.py プロジェクト: allanice001/geofront
def test_get_identity_403(fx_app, fx_token_store, fx_token_id):
    expires_at = (datetime.datetime.now(datetime.timezone.utc) +
                  datetime.timedelta(hours=1))
    fx_token_store.set(fx_token_id,
                       Token(Identity(DummyTeam, 1, False), expires_at))
    with fx_app.test_request_context():
        try:
            result = get_identity(fx_token_id)
        except HTTPException as e:
            response = e.get_response(request.environ)
            assert response.status_code == 403
            data = json.loads(response.get_data())
            assert data['error'] == 'not-authorized'
        else:
            fail('get_identity() does not raise HTTPException, but returns ' +
                 repr(result))
コード例 #8
0
ファイル: remote_test.py プロジェクト: xymz/geofront
def test_group_metadata_permission_policy(key, separator):
    sep = separator or ' '
    remotes = {
        'web-1': Remote(
            'ubuntu', '192.168.0.5',
            metadata={key: sep.join(['web', 'a']), 'other': 'ignore'}
        ),
        'web-2': Remote(
            'ubuntu', '192.168.0.6',
            metadata={key: sep.join(['web', 'b']), 'other': 'ignore'}
        ),
        'web-3': Remote(
            'ubuntu', '192.168.0.7',
            metadata={key: sep.join(['web', 'c']), 'other': 'ignore'}
        ),
        'worker-1': Remote(
            'ubuntu', '192.168.0.25',
            metadata={key: sep.join(['worker', 'a']), 'other': 'ignore'}
        ),
        'worker-2': Remote(
            'ubuntu', '192.168.0.26',
            metadata={key: sep.join(['worker', 'b']), 'other': 'ignore'}
        ),
        'db-1': Remote(
            'ubuntu', '192.168.0.50',
            metadata={key: sep.join(['db', 'a']), 'other': 'ignore'}
        ),
        'db-2': Remote(
            'ubuntu', '192.168.0.51',
            metadata={key: sep.join(['db', 'b']), 'other': 'ignore'}
        )
    }

    def subset(*keys):
        return {a: r for a, r in remotes.items() if a in keys}
    p = GroupMetadataPermissionPolicy(key, separator)
    identity = Identity(DummyTeam, 1)
    assert (p.filter(remotes, identity, {'web', 'a'}) ==
            subset('web-1', 'web-2', 'web-3', 'worker-1', 'db-1'))
    assert (p.filter(remotes, identity, {'db', 'c'}) ==
            subset('web-3', 'worker-3', 'db-1', 'db-2'))
    assert p.permit(remotes['db-1'], identity, {'web', 'a'})
    assert not p.permit(remotes['db-1'], identity, {'web', 'b'})
    assert p.permit(remotes['db-1'], identity, {'db', 'a'})
    assert p.permit(remotes['db-1'], identity, {'db', 'b'})
コード例 #9
0
ファイル: cloud_test.py プロジェクト: haegyung/geofront
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
コード例 #10
0
def test_identity_hash():
    assert hash(Identity(int, 1)) == hash(Identity(int, 1))
コード例 #11
0
ファイル: server_test.py プロジェクト: allanice001/geofront
def fx_authorized_identity(fx_token_store, fx_token_id):
    identity = Identity(DummyTeam, 1, True)
    expires_at = (datetime.datetime.now(datetime.timezone.utc) +
                  datetime.timedelta(hours=1))
    fx_token_store.set(fx_token_id, Token(identity, expires_at))
    return identity
コード例 #12
0
ファイル: identity_test.py プロジェクト: xymz/geofront
def test_identity_ne():
    assert not (Identity(DummyTeamA, 1) != Identity(DummyTeamA, 1))
    assert Identity(DummyTeamA, 1) != Identity(DummyTeamA, 2)
    assert Identity(DummyTeamA, 1) != Identity(DummyTeamB, 1)
    assert Identity(DummyTeamA, 1) != Identity(DummyTeamB, 2)
コード例 #13
0
def test_db_key_store(fx_db_key_store):
    identity = Identity(DummyTeam, 'abcd')
    assert_keystore_compliance(fx_db_key_store, identity)
    identity2 = Identity(DummyTeam, 'efg')
    assert_keystore_compliance(fx_db_key_store, identity2)
コード例 #14
0
ファイル: identity_test.py プロジェクト: xymz/geofront
def test_identity_hash():
    assert hash(Identity(DummyTeamA, 1)) == hash(Identity(DummyTeamA, 1))
コード例 #15
0
def fx_github_identity(fx_github_access_token: str) -> Identity:
    resp = request(fx_github_access_token, 'https://api.github.com/user',
                   'GET')
    return Identity(GitHubOrganization, resp['login'], fx_github_access_token)
コード例 #16
0
def fx_bitbucket_identity(fx_bitbucket_access_token: str) -> Identity:
    resp = request(fx_bitbucket_access_token,
                   'https://api.bitbucket.org/2.0/user', 'GET')
    return Identity(BitbucketTeam, resp['username'], fx_bitbucket_access_token)
コード例 #17
0
def test_identity_eq():
    assert Identity(int, 1) == Identity(int, 1)
    assert not (Identity(int, 1) == Identity(int, 2))
    assert not (Identity(int, 1) == Identity(str, 1))
    assert not (Identity(int, 1) == Identity(str, 2))
コード例 #18
0
ファイル: identity_test.py プロジェクト: xymz/geofront
def test_identity_eq():
    assert Identity(DummyTeamA, 1) == Identity(DummyTeamA, 1)
    assert not (Identity(DummyTeamA, 1) == Identity(DummyTeamA, 2))
    assert not (Identity(DummyTeamA, 1) == Identity(DummyTeamB, 1))
    assert not (Identity(DummyTeamA, 1) == Identity(DummyTeamB, 2))
コード例 #19
0
def test_identity_ne():
    assert not (Identity(int, 1) != Identity(int, 1))
    assert Identity(int, 1) != Identity(int, 2)
    assert Identity(int, 1) != Identity(str, 1)
    assert Identity(int, 1) != Identity(str, 2)