-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from Qabel/m/2
Identify identities only by public key
- Loading branch information
Showing
5 changed files
with
79 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.6 on 2016-09-26 16:18 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('index_service', '0003_singular_data_model'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='entry', | ||
name='field', | ||
field=models.CharField(choices=[('email', 'E-Mail address'), ('phone', 'Phone number')], db_index=True, max_length=30), | ||
), | ||
migrations.AlterField( | ||
model_name='identity', | ||
name='public_key', | ||
field=models.CharField(db_index=True, max_length=64, unique=True), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='identity', | ||
unique_together=set([]), | ||
), | ||
migrations.AlterIndexTogether( | ||
name='identity', | ||
index_together=set([]), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
from django.core import mail | ||
from django.core.cache import cache | ||
from django.forms.models import model_to_dict | ||
|
||
from rest_framework import status | ||
|
||
|
@@ -88,7 +89,8 @@ def test_match_is_exact(self, search_client, email_entry): | |
assert not response.data['identities'] | ||
|
||
def test_cross_identity(self, search_client, email_entry, identity): | ||
identity2 = Identity(alias='1234', drop_url='http://127.0.0.1:6000/qabel_1234', public_key=identity.public_key) | ||
pk2 = identity.public_key.replace('8520', '1234') | ||
identity2 = Identity(alias='1234', drop_url='http://127.0.0.1:6000/qabel_1234', public_key=pk2) | ||
identity2.save() | ||
phone1, phone2 = '+491234', '+491235' | ||
email = '[email protected]' | ||
|
@@ -103,17 +105,6 @@ def test_cross_identity(self, search_client, email_entry, identity): | |
identities = response.data['identities'] | ||
assert len(identities) == 2 | ||
|
||
expected1 = { | ||
'alias': '1234', | ||
'drop_url': 'http://127.0.0.1:6000/qabel_1234', | ||
'public_key': identity.public_key, | ||
'matches': [ | ||
{'field': 'email', 'value': email}, | ||
{'field': 'phone', 'value': phone1}, | ||
] | ||
} | ||
assert expected1 in identities | ||
|
||
def test_unknown_field(self, search_client): | ||
response = search_client({'no such field': '...'}) | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json() | ||
|
@@ -140,15 +131,17 @@ def _update_request_with_no_verification(self, api_client, mocker, simple_identi | |
# Short-cut verification to execution | ||
mocker.patch.object(UpdateRequest, 'start_verification', lambda self, *_: self.execute()) | ||
response = api_client.put(self.path, request, content_type='application/json', **kwargs) | ||
assert response.status_code == status.HTTP_204_NO_CONTENT | ||
assert response.status_code == status.HTTP_204_NO_CONTENT, response.json() | ||
|
||
def _search(self, api_client, what): | ||
response = api_client.get(SearchTest.path, what) | ||
assert response.status_code == status.HTTP_200_OK, response.json() | ||
result = response.data['identities'] | ||
assert len(result) == 1 | ||
assert result[0]['alias'] == 'public alias' | ||
assert result[0]['drop_url'] == 'http://example.com' | ||
identity = result[0] | ||
assert identity['alias'] == 'public alias' | ||
assert identity['drop_url'] == 'http://example.com' | ||
return identity | ||
|
||
def test_create(self, api_client, mocker, simple_identity): | ||
email = 'onlypeople_who_knew_this_address_already_can_find_the_entry@example.com' | ||
|
@@ -159,6 +152,23 @@ def test_create(self, api_client, mocker, simple_identity): | |
}]) | ||
self._search(api_client, {'email': email}) | ||
|
||
def test_change_alias(self, api_client, mocker, simple_identity): | ||
email = 'onlypeople_who_knew_this_address_already_can_find_the_entry@example.com' | ||
self._update_request_with_no_verification(api_client, mocker, simple_identity, [{ | ||
'action': 'create', | ||
'field': 'email', | ||
'value': email, | ||
}]) | ||
identity = self._search(api_client, {'email': email}) | ||
simple_identity['alias'] = 'foo the bar' | ||
self._update_request_with_no_verification(api_client, mocker, simple_identity, []) | ||
response = api_client.get(SearchTest.path, {'email': email}) | ||
assert response.status_code == status.HTTP_200_OK, response.json() | ||
result = response.data['identities'] | ||
assert len(result) == 1 | ||
identity = result[0] | ||
assert identity['alias'] == 'foo the bar' | ||
|
||
@pytest.mark.parametrize('accept_language', ( | ||
'de-de', # an enabled language, also the default | ||
'ko-kr', # best korea | ||
|
@@ -207,7 +217,7 @@ def delete_prerequisite(self, api_client, email_entry): | |
message = mail.outbox.pop() | ||
assert message.to == [email_entry.value] | ||
message_context = message.context | ||
assert message_context['identity'] == email_entry.identity | ||
assert message_context['identity']._asdict() == model_to_dict(email_entry.identity, exclude=['id']) | ||
|
||
return message_context | ||
|
||
|
@@ -233,9 +243,7 @@ def test_delete_deny(self, api_client, delete_prerequisite, email_entry): | |
assert Entry.objects.filter(value=email_entry.value).count() == 1 | ||
|
||
@pytest.mark.parametrize('invalid_request', [ | ||
{}, | ||
{'items': "a string?"}, | ||
{'items': []}, | ||
{ | ||
'items': [ | ||
{ | ||
|