def test_can_encrypt_record(self):
     report = Report(owner=self.user)
     report.encrypt_record("this text should be encrypted",
                           "this is my key")
     self.assertIsNotNone(report.encode_prefix)
     self.assertNotEqual(report.encode_prefix, "")
     self.assertIsNotNone(report.encrypted)
     self.assertTrue(len(report.encrypted) > 0)
 def test_entered_into_matching_is_blank_before_entering_into_matching(
         self):
     report = Report(owner=self.user)
     report.encrypt_record("test non-matching report", "key")
     report.save()
     self.assertIsNone(
         Report.objects.get(
             pk=report.id).entered_into_matching)
    def test_gpg_decryption(self):
        report = Report()
        report._store_for_callisto_decryption({'rawr': 'cats'})

        gpg = gnupg.GPG()
        gpg.import_keys(test_keypair.private_test_key)
        gpg_data = gpg.decrypt(report.encrypted_eval)
        data = json.loads(gpg_data.data)

        self.assertEqual(data, {'rawr': 'cats'})
 def test_can_encrypt_record(self):
     report = Report(owner=self.user)
     report.encrypt_record(
         "this text should be encrypted",
         'this is my key',
     )
     self.assertIsNotNone(report.encode_prefix)
     self.assertNotEqual(report.encode_prefix, '')
     self.assertIsNotNone(report.encrypted)
     self.assertTrue(len(report.encrypted) > 0)
Example #5
0
class MatchSetup(TestCase):

    fixtures = [
        'callisto_core_notification_data',
    ]

    def setUp(self):
        self.site = Site.objects.get(id=1)
        self.site.domain = 'testserver'
        self.site.save()
        self.user1 = User.objects.create_user(
            username="******",
            password="******",
        )
        self.user2 = User.objects.create_user(
            username="******",
            password="******",
        )
        self.user3 = User.objects.create_user(
            username="******",
            password="******",
        )
        self.user4 = User.objects.create_user(
            username="******",
            password="******",
        )

    def assert_matches_found_true(self):
        self.assert_matches_found(self.assertTrue)

    def assert_matches_found_false(self):
        self.assert_matches_found(self.assertFalse)

    def assert_matches_found(self, assertion):
        for match in MatchReport.objects.all():
            assertion(match.match_found)

    def create_match(self, user, identifier):
        self.most_recent_report = Report(owner=user)
        self.most_recent_report.encrypt_record("test report 1", "key")
        match_report = MatchReport(report=self.most_recent_report)
        match_report_content = MatchReportContent(
            identifier=identifier,
            perp_name=identifier,
            email='*****@*****.**',
            phone="123",
        )
        match_report.encrypt_match_report(
            json.dumps(match_report_content.__dict__),
            identifier,
        )

        matches = MatchingApi.find_matches(identifier)
        return matches
 def test_can_decrypt_report(self):
     report = Report(owner=self.user)
     report.encrypt_record(
         "this text should be encrypted, yes it should by golly!",
         'this is my key',
     )
     report.save()
     saved_report = Report.objects.first()
     self.assertEqual(
         saved_report.decrypt_record('this is my key'),
         "this text should be encrypted, yes it should by golly!",
     )
 def test_can_decrypt_old_reports(self):
     legacy_report = LegacyReportData()
     legacy_report.encrypt_record(
         "this text should be encrypted otherwise bad things",
         key="this is my key")
     report = Report(owner=self.user,
                     encrypted=legacy_report.encrypted,
                     salt=legacy_report.salt)
     report.save()
     saved_report = Report.objects.first()
     self.assertEqual(
         saved_report.decrypt_record("this is my key"),
         "this text should be encrypted otherwise bad things",
     )
Example #8
0
    def create_match(self, user, identifier):
        self.most_recent_report = Report(owner=user)
        self.most_recent_report.encrypt_record("test report 1", "key")
        match_report = MatchReport(report=self.most_recent_report)
        match_report_content = MatchReportContent(
            identifier=identifier,
            perp_name=identifier,
            email="*****@*****.**",
            phone="123",
        )
        match_report.encrypt_match_report(
            json.dumps(match_report_content.__dict__), identifier)

        matches = MatchingApi.find_matches(identifier)
        return matches
class MatchSetup(TestCase):

    fixtures = [
        'callisto_core_notification_data',
    ]

    def setUp(self):
        self.site = Site.objects.get(id=1)
        self.site.domain = 'testserver'
        self.site.save()
        self.user1 = User.objects.create_user(
            username="******", password="******",
        )
        self.user2 = User.objects.create_user(
            username="******", password="******",
        )
        self.user3 = User.objects.create_user(
            username="******", password="******",
        )
        self.user4 = User.objects.create_user(
            username="******", password="******",
        )

    def assert_matches_found_true(self):
        self.assert_matches_found(self.assertTrue)

    def assert_matches_found_false(self):
        self.assert_matches_found(self.assertFalse)

    def assert_matches_found(self, assertion):
        for match in MatchReport.objects.all():
            assertion(match.match_found)

    def create_match(self, user, identifier):
        self.most_recent_report = Report(owner=user)
        self.most_recent_report.encrypt_record("test report 1", "key")
        match_report = MatchReport(report=self.most_recent_report)
        match_report_content = MatchReportContent(
            identifier=identifier, perp_name=identifier,
            email='*****@*****.**', phone="123",
        )
        match_report.encrypt_match_report(
            json.dumps(match_report_content.__dict__),
            identifier,
        )

        matches = MatchingApi.find_matches(identifier)
        return matches
 def test_can_decrypt_old_reports(self):
     legacy_report = LegacyReportData()
     legacy_report.encrypt_record(
         "this text should be encrypted otherwise bad things",
         key='this is my key',
     )
     report = Report(
         owner=self.user,
         encrypted=legacy_report.encrypted,
         salt=legacy_report.salt,
     )
     report.save()
     saved_report = Report.objects.first()
     self.assertEqual(
         saved_report.decrypt_record('this is my key'),
         "this text should be encrypted otherwise bad things",
     )
Example #11
0
 def test_entered_into_matching_is_blank_before_entering_into_matching(
         self):
     report = Report(owner=self.user)
     report.encrypt_record("test non-matching report", "key")
     report.save()
     self.assertIsNone(
         Report.objects.get(pk=report.id).entered_into_matching)
Example #12
0
    def test_can_decrypt_old_match_report(self):
        legacy_match_report = LegacyMatchReportData()
        legacy_match_report.encrypt_match_report("test legacy match report",
                                                 "dumbo")

        legacy_report = LegacyReportData()
        legacy_report.encrypt_record(
            "this text should be encrypted otherwise bad things",
            key='this is my key')
        report = Report(owner=self.user,
                        encrypted=legacy_report.encrypted,
                        salt=legacy_report.salt)
        report.save()

        new_match_report = MatchReport(
            report=report,
            encrypted=legacy_match_report.encrypted,
            salt=legacy_match_report.salt,
        )
        new_match_report.save()
        self.assertEqual(new_match_report.get_match("dumbo"),
                         "test legacy match report")
 def test_deleted_report_doesnt_delete_sent_match_report(self):
     match_report = MatchReport(report=self.report)
     match_report.encrypt_match_report("test match report", 'dummy')
     match_report.save()
     user2 = User.objects.create_user(username="******", password="******")
     report2 = Report(owner=user2)
     report2.encrypt_record("test report 2", "key")
     report2.save()
     match_report2 = MatchReport(report=report2)
     match_report2.encrypt_match_report("test match report 2", 'dummy')
     match_report2.save()
     sent_match_report = SentMatchReport.objects.create()
     sent_match_report.reports.add(match_report, match_report2)
     self.report.match_found = True
     self.report.save()
     report2.match_found = True
     report2.save()
     self.assertIsNotNone(match_report.sentmatchreport_set.first())
     self.assertIsNotNone(match_report2.sentmatchreport_set.first())
     self.assertEqual(
         match_report,
         SentMatchReport.objects.first().reports.all()[0])
     self.assertEqual(
         match_report2,
         SentMatchReport.objects.first().reports.all()[1])
     self.report.delete()
     self.assertEqual(Report.objects.count(), 1)
     self.assertEqual(MatchReport.objects.count(), 1)
     self.assertEqual(SentMatchReport.objects.first(), sent_match_report)
     self.assertEqual(SentMatchReport.objects.first().reports.count(), 1)
     self.assertEqual(
         SentMatchReport.objects.first().reports.first(),
         match_report2)
     self.assertTrue(Report.objects.first().match_found)
     report2.delete()
     self.assertEqual(Report.objects.count(), 0)
     self.assertEqual(SentMatchReport.objects.first(), sent_match_report)
    def create_match(self, user, identifier):
        self.most_recent_report = Report(owner=user)
        self.most_recent_report.encrypt_record("test report 1", "key")
        match_report = MatchReport(report=self.most_recent_report)
        match_report_content = MatchReportContent(
            identifier=identifier, perp_name=identifier,
            email='*****@*****.**', phone="123",
        )
        match_report.encrypt_match_report(
            json.dumps(match_report_content.__dict__),
            identifier,
        )

        matches = MatchingApi.find_matches(identifier)
        return matches
    def test_can_decrypt_old_match_report(self):
        legacy_match_report = LegacyMatchReportData()
        legacy_match_report.encrypt_match_report(
            "test legacy match report", "dumbo")

        legacy_report = LegacyReportData()
        legacy_report.encrypt_record(
            "this text should be encrypted otherwise bad things",
            key='this is my key')
        report = Report(
            owner=self.user,
            encrypted=legacy_report.encrypted,
            salt=legacy_report.salt)
        report.save()

        new_match_report = MatchReport(
            report=report,
            encrypted=legacy_match_report.encrypted,
            salt=legacy_match_report.salt,
        )
        new_match_report.save()
        self.assertEqual(
            new_match_report.get_match("dumbo"),
            "test legacy match report")
 def test_can_decrypt_report(self):
     report = Report(owner=self.user)
     report.encrypt_record(
         "this text should be encrypted, yes it should by golly!",
         "this is my key")
     report.save()
     saved_report = Report.objects.first()
     self.assertEqual(
         saved_report.decrypt_record("this is my key"),
         "this text should be encrypted, yes it should by golly!",
     )
Example #17
0
 def test_can_withdraw_from_matching(self):
     report = Report(owner=self.user)
     report.encrypt_record("test report", "key")
     report.save()
     MatchReport.objects.create(report=report)
     self.assertIsNotNone(Report.objects.first().entered_into_matching)
     report.match_found = True
     report.save()
     report.withdraw_from_matching()
     report.save()
     self.assertIsNone(Report.objects.first().entered_into_matching)
     self.assertFalse(Report.objects.first().match_found)
Example #18
0
 def test_no_times_by_default(self):
     report = Report(owner=self.user)
     report.encrypt_record("test report", "key")
     report.save()
     self.assertIsNone(Report.objects.first().submitted_to_school)
     self.assertIsNone(Report.objects.first().entered_into_matching)
Example #19
0
 def test_deleted_report_doesnt_delete_sent_match_report(self):
     match_report = MatchReport(report=self.report)
     match_report.encrypt_match_report("test match report", 'dummy')
     match_report.save()
     user2 = User.objects.create_user(username="******", password="******")
     report2 = Report(owner=user2)
     report2.encrypt_record("test report 2", "key")
     report2.save()
     match_report2 = MatchReport(report=report2)
     match_report2.encrypt_match_report("test match report 2", 'dummy')
     match_report2.save()
     sent_match_report = SentMatchReport.objects.create()
     sent_match_report.reports.add(match_report, match_report2)
     self.report.match_found = True
     self.report.save()
     report2.match_found = True
     report2.save()
     self.assertIsNotNone(match_report.sentmatchreport_set.first())
     self.assertIsNotNone(match_report2.sentmatchreport_set.first())
     self.assertEqual(match_report,
                      SentMatchReport.objects.first().reports.all()[0])
     self.assertEqual(match_report2,
                      SentMatchReport.objects.first().reports.all()[1])
     self.report.delete()
     self.assertEqual(Report.objects.count(), 1)
     self.assertEqual(MatchReport.objects.count(), 1)
     self.assertEqual(SentMatchReport.objects.first(), sent_match_report)
     self.assertEqual(SentMatchReport.objects.first().reports.count(), 1)
     self.assertEqual(SentMatchReport.objects.first().reports.first(),
                      match_report2)
     self.assertTrue(Report.objects.first().match_found)
     report2.delete()
     self.assertEqual(Report.objects.count(), 0)
     self.assertEqual(SentMatchReport.objects.first(), sent_match_report)
Example #20
0
 def test_reports_have_owners(self):
     report = Report()
     report.owner = self.user
     report.save()
     self.assertIn(report, self.user.report_set.all())
 def test_can_withdraw_from_matching(self):
     report = Report(owner=self.user)
     report.encrypt_record("test report", "key")
     report.save()
     MatchReport.objects.create(report=report)
     self.assertIsNotNone(Report.objects.first().entered_into_matching)
     report.match_found = True
     report.save()
     report.withdraw_from_matching()
     report.save()
     self.assertIsNone(Report.objects.first().entered_into_matching)
     self.assertFalse(Report.objects.first().match_found)
 def test_no_times_by_default(self):
     report = Report(owner=self.user)
     report.encrypt_record("test report", "key")
     report.save()
     self.assertIsNone(Report.objects.first().submitted_to_school)
     self.assertIsNone(Report.objects.first().entered_into_matching)
 def test_reports_have_owners(self):
     report = Report()
     report.owner = self.user
     report.save()
     self.assertIn(report, self.user .report_set.all())