This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+30 -38
View File
@@ -19,40 +19,38 @@ def store(hass):
@pytest.fixture
def provider(hass, store):
"""Mock provider."""
return insecure_example.ExampleAuthProvider(hass, store, {
'type': 'insecure_example',
'users': [
{
'name': 'Test Name',
'username': 'user-test',
'password': 'password-test',
},
{
'username': '🎉',
'password': '😎',
}
]
})
return insecure_example.ExampleAuthProvider(
hass,
store,
{
"type": "insecure_example",
"users": [
{
"name": "Test Name",
"username": "user-test",
"password": "password-test",
},
{"username": "🎉", "password": "😎"},
],
},
)
@pytest.fixture
def manager(hass, store, provider):
"""Mock manager."""
return AuthManager(hass, store, {
(provider.type, provider.id): provider
}, {})
return AuthManager(hass, store, {(provider.type, provider.id): provider}, {})
async def test_create_new_credential(manager, provider):
"""Test that we create a new credential."""
credentials = await provider.async_get_or_create_credentials({
'username': 'user-test',
'password': 'password-test',
})
credentials = await provider.async_get_or_create_credentials(
{"username": "user-test", "password": "password-test"}
)
assert credentials.is_new is True
user = await manager.async_get_or_create_user(credentials)
assert user.name == 'Test Name'
assert user.name == "Test Name"
assert user.is_active
@@ -60,39 +58,33 @@ async def test_match_existing_credentials(store, provider):
"""See if we match existing users."""
existing = auth_models.Credentials(
id=uuid.uuid4(),
auth_provider_type='insecure_example',
auth_provider_type="insecure_example",
auth_provider_id=None,
data={
'username': 'user-test'
},
data={"username": "user-test"},
is_new=False,
)
provider.async_credentials = Mock(return_value=mock_coro([existing]))
credentials = await provider.async_get_or_create_credentials({
'username': 'user-test',
'password': 'password-test',
})
credentials = await provider.async_get_or_create_credentials(
{"username": "user-test", "password": "password-test"}
)
assert credentials is existing
async def test_verify_username(provider):
"""Test we raise if incorrect user specified."""
with pytest.raises(insecure_example.InvalidAuthError):
await provider.async_validate_login(
'non-existing-user', 'password-test')
await provider.async_validate_login("non-existing-user", "password-test")
async def test_verify_password(provider):
"""Test we raise if incorrect user specified."""
with pytest.raises(insecure_example.InvalidAuthError):
await provider.async_validate_login(
'user-test', 'incorrect-password')
await provider.async_validate_login("user-test", "incorrect-password")
async def test_utf_8_username_password(provider):
"""Test that we create a new credential."""
credentials = await provider.async_get_or_create_credentials({
'username': '🎉',
'password': '😎',
})
credentials = await provider.async_get_or_create_credentials(
{"username": "🎉", "password": "😎"}
)
assert credentials.is_new is True