示例#1
0
文件: test_simple.py 项目: em-2/em2
async def test_check_domain():
    auth = SimpleAuthenticator()
    auth.valid_signature_override = True
    ts = int(datetime.now().strftime('%s'))
    platform_token = await auth.authenticate_platform('testing.foobar.com', ts, 'anything')
    domain = await auth.valid_platform_token(platform_token)
    await auth.check_domain_platform('foobar.com', domain)
示例#2
0
文件: test_simple.py 项目: em-2/em2
async def test_invalid_public_key():
    auth = SimpleAuthenticator()
    auth.public_key_value = 'whatever'
    auth._now_unix = lambda: TS

    with pytest.raises(FailedInboundAuthentication) as excinfo:
        await auth.authenticate_platform(PLATFORM, TIMESTAMP, VALID_SIGNATURE)
    assert excinfo.value.args[0] == 'RSA key format is not supported'
示例#3
0
文件: test_simple.py 项目: em-2/em2
async def test_check_domain_missing():
    auth = SimpleAuthenticator()
    auth.valid_signature_override = True
    ts = int(datetime.now().strftime('%s'))
    platform_token = await auth.authenticate_platform('testing.foobar.com', ts, 'anything')
    token = await auth.valid_platform_token(platform_token)
    with pytest.raises(DomainPlatformMismatch) as excinfo:
        await auth.check_domain_platform('bang.com', token)
    assert excinfo.value.args[0] == '"bang.com" does not use "testing.foobar.com"'
示例#4
0
文件: test_simple.py 项目: em-2/em2
async def test_key_does_exists():
    auth = SimpleAuthenticator()
    auth.valid_signature_override = True

    # note: strftime('%s') has to be used with now() to avoid double tz conversion
    n = int(datetime.now().strftime('%s'))

    platform_key = await auth.authenticate_platform('foobar.com', n, 'foobar')
    platform, exp, rand = platform_key.split(':', 2)
    assert platform == 'foobar.com'
    assert 86390 < (int(exp) - n) < 86410
    assert len(rand) == 64

    await auth.valid_platform_token(platform_key)
示例#5
0
文件: test_simple.py 项目: em-2/em2
async def test_key_verification_old_ts():
    auth = SimpleAuthenticator()
    auth._now_unix = lambda: TS
    with pytest.raises(FailedInboundAuthentication) as excinfo:
        await auth.authenticate_platform('foobar.com', 2461449100, VALID_SIGNATURE)
    assert excinfo.value.args[0] == '2461449100 was not between 2461449590 and 2461449601'
示例#6
0
文件: test_simple.py 项目: em-2/em2
async def test_key_verification_bad_signature():
    auth = SimpleAuthenticator()
    auth._now_unix = lambda: TS
    with pytest.raises(FailedInboundAuthentication) as excinfo:
        await auth.authenticate_platform(PLATFORM, TIMESTAMP, VALID_SIGNATURE.replace('2', '3'))
    assert excinfo.value.args[0] == 'invalid signature'
示例#7
0
文件: test_simple.py 项目: em-2/em2
async def test_key_verification():
    auth = SimpleAuthenticator()
    auth._now_unix = lambda: TS

    platform_key = await auth.authenticate_platform(PLATFORM, TIMESTAMP, VALID_SIGNATURE)
    await auth.valid_platform_token(platform_key)
示例#8
0
文件: conftest.py 项目: em-2/em2
def _create_app(loop):
    ds = SimpleDataStore()
    ctrl = Controller(ds)
    auth = SimpleAuthenticator()
    auth._now_unix = lambda: 2461449600
    return create_app(ctrl, auth, loop=loop)