def setUpSafe(self): super().setUpSafe() self.post = Post() self.post.server = self.server self.post.path = '/post1' self.post.data = { 'body': 'How are you?', } self.post.save() UserPostRelation.create(source=self.abraham, type='wrote', target=self.post) event = Event() event.server = 'aaa' event.authors = ['bernard@aaa'] event.parent = 'aaa/post1' event.path = '/post1#c1' event.data = {'body': 'Good!'} event.signatures = { 'bernard@aaa': sign_post(event, self.bernard_keypair).hex(), } event.save() process_event(event)
def test_sign(self): self.assertEqual( sign_post(self.event, self.abraham_keypair, data={ 'foo': 'bar', 'bar': 'baz' }), self.expected)
def sign_post_incorrectly(obj: Union[Post, Event], keypair: KeyPair, **kwargs) -> bytes: """ Generates incorrect signature for the object. It's like normal :func:`sign_post()`, but incorrect. """ hex = sign_post(obj, keypair, **kwargs).hex().replace('a', 'b') return bytes.fromhex(hex)
def setUpSafe(self): super().setUpSafe() self.event = Event() self.event.server = 'aaa' self.event.authors = ['abraham@aaa'] self.event.path = '/post1' self.event.diff = { 'body': 'Some text here.', } self.event.signatures = { 'abraham@aaa': sign_post(self.event, self.get_abraham2()).hex(), } self.event.save()
def setUpSafe(self): super().setUpSafe() self.event = Event() self.event.server = 'aaa' self.event.authors = ['abraham@aaa'] self.event.path = '/post1' self.event.diff = { 'body': 'Hello, World!', 'tags': ['Aaa', 'Bbb', 'Ccc'], } self.event.signatures = { 'abraham@aaa': sign_post(self.event, self.abraham_keypair).hex(), } self.event.save() process_event(self.event)
def setUpSafe(self): super().setUpSafe() self.event = Event() self.event.server = 'aaa' self.event.authors = ['abraham@aaa'] self.event.path = '/post1' self.event.diff = { 'body': 'This event should be rejected.', } self.event.signatures = { 'abraham@aaa': sign_post_incorrectly(self.event, self.abraham_keypair).hex(), 'bernard@aaa': sign_post(self.event, self.bernard_keypair).hex(), } self.event.save()
def setUpSafe(self): super().setUpSafe() self.post = Post() self.post.server = self.server self.post.authors = [self.abraham] self.post.path = '/post1' self.post.data = { 'title': 'Hello', 'subtitle': 'A hello world post', 'body': 'Hello, World!', } self.post.save() event = Event() event.server = 'aaa' event.authors = ['abraham@aaa'] event.path = '/post1' event.diff = { 'title': 'Hello (updated)', 'subtitle': None, 'tags': ['Aaa', 'Bbb', 'Ccc'], } event.signatures = { 'abraham@aaa': sign_post(event, self.abraham_keypair, data={ 'title': 'Hello (updated)', 'body': 'Hello, World!', 'tags': ['Aaa', 'Bbb', 'Ccc'], }).hex(), } event.save() process_event(event) self.post.reload()
def test_sign(self): self.assertEqual(sign_post(self.event, self.abraham_keypair), self.expected)