def test_lists_blocked(self, blocked_credential, account): with freeze_time('2016-01-04'): create_credential(account, 'blocked2.exe', 'normal') date_range = (datetime(2016, 1, 1), datetime(2016, 1, 10)) with report_csv(date_range) as fd: report = fd.getvalue() report_lines = report.split() assert len(report_lines) == 2 assert f'"{report_lines[1][0]},{report_lines[1][1]}"'
def test_creation_date_filtering(self, credentials, other_account): with freeze_time('2016-01-10'): cred = create_credential(other_account, 'moved.jpg', 'normal') cred.status = CredentialStatus.Moved.value cred.save() cred = create_credential(other_account, 'not_found.jpg', 'normal') cred.status = CredentialStatus.NotFound.value cred.save() date_range = (datetime(2016, 1, 1), datetime(2016, 1, 7)) with report_csv(date_range) as fd: report = fd.getvalue() report_lines = report.split() assert len(report_lines) == 2 assert report_lines[1].startswith('"12345678"')
def test_blocked_query(self, account, credentials): cred = create_credential(account, 'asdf.jpg', 'normal') cred.mark_as_blocked() blocked = Credential.objects.blocked() assert blocked.count() == 2 assert blocked[0].is_blocked is True assert blocked[1].is_blocked is True
def test_not_found_query(self, account, credentials): cred = create_credential(account, 'asdf.jpg', 'normal') cred.status = CredentialStatus.NotFound.value cred.save() not_found = Credential.objects.not_found() assert not_found.count() == 2 assert not_found[0].status == CredentialStatus.NotFound.value assert not_found[1].status == CredentialStatus.NotFound.value
def test_filters_credentials_by_creation_date(self, move_creds_mock, account): with freeze_time('2016-01-01'): cred1 = collector_domain.create_credential(account, 'zxcv.jpg', 'normal') cred1.mark_as_found() with freeze_time('2016-02-01'): cred2 = collector_domain.create_credential(account, 'zxcv.jpg', 'normal') cred2.mark_as_found() with freeze_time('2016-02-01'): move() args, kwargs = move_creds_mock.call_args assert move_creds_mock.call_count == 1 assert len(args) == 1 assert len(args[0]) == 1 assert args[0][0] == cred1
def test_moved_query(self, account, credentials): cred = create_credential(account, 'asdf.jpg', 'normal') cred.status = CredentialStatus.Moved.value cred.save() moved = Credential.objects.moved() assert moved.count() == 2 assert moved[0].status == CredentialStatus.Moved.value assert moved[1].status == CredentialStatus.Moved.value
def test_lists_not_found(self, not_found_credential, account): with freeze_time('2016-01-04'): cred = create_credential(account, 'not--found.jpg', 'normal') cred.status = CredentialStatus.NotFound.value cred.save() date_range = (datetime(2016, 1, 1), datetime(2016, 1, 10)) with report_csv(date_range) as fd: report = fd.getvalue() report_lines = report.split() assert len(report_lines) == 2 assert f'"{report_lines[1][0]},{report_lines[1][1]}"'
def test_moves_only_credentials_need_moving(self, move_creds_mock, credentials, account): with freeze_time('2016-01-05'): found2 = collector_domain.create_credential( account, 'zxcv.jpg', 'normal') found2.mark_as_found() need_moving = Credential.objects.need_moving() call_command('move') args, kwargs = move_creds_mock.call_args assert len(args[0]) == 4 assert need_moving[0] in args[0] assert need_moving[1] in args[0] assert need_moving[2] in args[0] assert need_moving[3] in args[0]
def test_missing_extension(self, account): cred = create_credential(account, 'file', 'normal') assert has_whitelisted_extension(cred) is False
def test_non_whitelisted_mixedcase_extension(self, account): cred = create_credential(account, 'file.exE', 'normal') assert has_whitelisted_extension(cred) is False
def test_whitelisted_mixedcase_extension(self, account): cred = create_credential(account, 'fILe.pNg', 'normal') assert has_whitelisted_extension(cred) is True
def test_whitelisted_lowercase_extension(self, account): cred = create_credential(account, 'file.jpg', 'normal') assert has_whitelisted_extension(cred) is True
def test_marked_as_blocked_if_blocked_extension(self, account): cred = create_credential(account, 'awesome.exe', 'normal') assert cred.is_blocked is True
def blocked_credential(account): return collector_domain.create_credential(account, 'blocked.exe', 'normal')
def test_consecutive_s3_filename_generation(self, account): cred1 = create_credential(account, 'awesome.jpg', 'normal') cred2 = create_credential(account, 'sexy.jpg', 'normal') assert cred1.s3_key == 'normal_12345678_1.jpg' assert cred2.s3_key == 'normal_12345678_2.jpg'
def moved_credential(account): cred = collector_domain.create_credential(account, 'moved.jpg', 'normal') cred.status = CredentialStatus.Moved.value cred.save() return cred
def test_consecutive_s3_filename_generation_for_priority(self, account): cred1 = create_credential(account, 'awesome.jpg', 'priority') cred2 = create_credential(account, 'sexy.jpg', 'priority') assert cred1.s3_key == 'priority_12345678_1.jpg' assert cred2.s3_key == 'priority_12345678_2.jpg'
def not_found_credential(account): cred = collector_domain.create_credential(account, 'not_found.jpg', 'normal') cred.status = CredentialStatus.NotFound.value cred.save() return cred