Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #257 from atexio/pyup-update-django-2.0.7-to-2.2.1
Browse files Browse the repository at this point in the history
Update django to 2.2.1
  • Loading branch information
y0no committed May 20, 2019
2 parents 9f420a8 + 991e279 commit 64db044
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 70 deletions.
32 changes: 29 additions & 3 deletions phishing/tests/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
import os

from shutil import copyfile
from datetime import timedelta

from django.conf import settings
from django.core.exceptions import SuspiciousOperation
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
from django.urls import reverse
from django.utils.timezone import now

from phishing.models import Attachment, Tracker
from phishing.models import Campaign
from phishing.models import EmailTemplate
from phishing.strings import TRACKER_ATTACHMENT_EXECUTED
from phishing.tests.constant import FILES_PATH, FIXTURE_PATH

Expand All @@ -21,7 +25,25 @@ class AttachmentTestCase(TestCase):
os.path.join(FIXTURE_PATH, 'user.json'),
]

def _create_campaign(self):
# add email template
email_template = EmailTemplate.objects.create(
email_subject='Hello!',
from_email='account@example.com',
name='email template name',
text_content='Goodbye!',
)

# create campaign
return Campaign.objects.create(
email_template=email_template,
name='test group graph',
send_at=now() + timedelta(hours=1)
)

def test_build(self):
campaign = self._create_campaign()

attachment_name = 'build.json'
attachment_path = os.path.join(settings.MEDIA_ROOT, 'test_attachment')
copyfile(os.path.join(FILES_PATH, 'archive.zip'), attachment_path)
Expand All @@ -34,7 +56,7 @@ def test_build(self):

kwargs = {
'key': TRACKER_ATTACHMENT_EXECUTED,
'campaign_id': 1,
'campaign_id': campaign.pk,
'target_id': 1,
'value': 'tracker: not opened',
}
Expand All @@ -53,6 +75,8 @@ def test_build(self):
os.remove(attachment_path)

def test_build_invalid_zip(self):
campaign = self._create_campaign()

attachment_name = 'build.json'
attachment_path = os.path.join(settings.MEDIA_ROOT, 'test_attachment')
copyfile(os.path.join(FILES_PATH, 'invalid_archive.zip'),
Expand All @@ -66,7 +90,7 @@ def test_build_invalid_zip(self):

kwargs = {
'key': TRACKER_ATTACHMENT_EXECUTED,
'campaign_id': 1,
'campaign_id': campaign.pk,
'target_id': 1,
'value': 'tracker: not opened',
}
Expand All @@ -75,6 +99,8 @@ def test_build_invalid_zip(self):
attachment.build(tracker)

def test_build_static(self):
campaign = self._create_campaign()

attachment_name = 'b64.png'
attachment_path = os.path.join(settings.MEDIA_ROOT, 'test_attachment')
copyfile(os.path.join(FILES_PATH, 'image.png'), attachment_path)
Expand All @@ -87,7 +113,7 @@ def test_build_static(self):

kwargs = {
'key': TRACKER_ATTACHMENT_EXECUTED,
'campaign_id': 1,
'campaign_id': campaign.pk,
'target_id': 1,
'value': 'tracker: not opened',
}
Expand Down
38 changes: 0 additions & 38 deletions phishing/tests/landing_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,44 +445,6 @@ def test_landing_page_view_invalid_post_id(self):
self.assertEqual(infos.raw,
'tracker_post_id of %s in unknown' % tracker.pk)

def test_landing_page_view_exception(self):
target = 'http://www.simplehtmlguide.com/examples/forms1.html'

# We create a landing page
lp = LandingPage.objects.create(
name='Test delete perm',
html=clone_url(target)
)

et = EmailTemplate.objects.create(
name='Test landing page view',
email_subject='foo bar',
text_content='lorem ipsum',
landing_page_id=lp.pk,
)

# We create a campaign
camp = Campaign.objects.create(
email_template_id=et.pk,
name='Test landing page campaign'
)
target_grp = TargetGroup.objects.get(pk=1)
camp.target_groups_add(target_grp)
self.assertTrue(camp.send())

tracker = camp.trackers.filter(key='landing_page_open').first()

# set incorrect value for make crash
tracker.campaign_id = 99999999
tracker.save()

resp = self.client.get(reverse('landing_page', args=(tracker.uuid,)))

# Strange behavior, google set multiple redirect.
# So we can't use "assertRedirect" function
self.assertEqual(resp.status_code, 302)
self.assertEqual(resp['Location'], 'https://www.google.com/')

def test_landing_page_post(self):
target = 'http://www.simplehtmlguide.com/examples/forms1.html'

Expand Down
48 changes: 24 additions & 24 deletions phishing/tests/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def test_form_target_invalid_name(self):
response = self.client.post(reverse("target_group_add"),
{
'name': '',
'targets-0-DELETE': None,
'targets-0-DELETE': '',
'targets-0-email': 'test@test.com',
'targets-0-first_name': None,
'targets-0-id': None,
'targets-0-last_name': None,
'targets-0-first_name': '',
'targets-0-id': '',
'targets-0-last_name': '',
'targets-INITIAL_FORMS': 0,
'targets-MAX_NUM_FORMS': 1000,
'targets-MIN_NUM_FORMS': 0,
Expand Down Expand Up @@ -67,11 +67,11 @@ def test_form_target_valid(self):
response = self.client.post(reverse("target_group_add"),
{
'name': 'OLOL',
'targets-0-DELETE': None,
'targets-0-DELETE': '',
'targets-0-email': 'test@test.com',
'targets-0-first_name': None,
'targets-0-id': None,
'targets-0-last_name': None,
'targets-0-first_name': '',
'targets-0-id': '',
'targets-0-last_name': '',
'targets-INITIAL_FORMS': 0,
'targets-MAX_NUM_FORMS': 1000,
'targets-MIN_NUM_FORMS': 0,
Expand All @@ -90,11 +90,11 @@ def test_print_target(self):
self.client.post(reverse("target_group_add"),
{
'name': 'OLOL',
'targets-0-DELETE': None,
'targets-0-DELETE': '',
'targets-0-email': 'test@test.com',
'targets-0-first_name': None,
'targets-0-id': None,
'targets-0-last_name': None,
'targets-0-first_name': '',
'targets-0-id': '',
'targets-0-last_name': '',
'targets-INITIAL_FORMS': 0,
'targets-MAX_NUM_FORMS': 1000,
'targets-MIN_NUM_FORMS': 0,
Expand All @@ -110,11 +110,11 @@ def test_form_target_edit(self):
self.client.post(reverse("target_group_add"),
{
'name': 'OLOL',
'targets-0-DELETE': None,
'targets-0-DELETE': '',
'targets-0-email': 'test@test.com',
'targets-0-first_name': None,
'targets-0-id': None,
'targets-0-last_name': None,
'targets-0-first_name': '',
'targets-0-id': '',
'targets-0-last_name': '',
'targets-INITIAL_FORMS': 0,
'targets-MAX_NUM_FORMS': 1000,
'targets-MIN_NUM_FORMS': 0,
Expand All @@ -127,11 +127,11 @@ def test_form_target_edit(self):
args=(targetGroup.pk,)),
{
'name': 'OLOLOL',
'targets-0-DELETE': None,
'targets-0-DELETE': '',
'targets-0-email': 'foo@test.com',
'targets-0-first_name': None,
'targets-0-id': None,
'targets-0-last_name': None,
'targets-0-first_name': '',
'targets-0-id': '',
'targets-0-last_name': '',
'targets-INITIAL_FORMS': 0,
'targets-MAX_NUM_FORMS': 1000,
'targets-MIN_NUM_FORMS': 0,
Expand All @@ -154,11 +154,11 @@ def test_form_target_delete(self):
self.client.post(reverse("target_group_add"),
{
'name': 'OLOL',
'targets-0-DELETE': None,
'targets-0-DELETE': '',
'targets-0-email': 'test@test.com',
'targets-0-first_name': None,
'targets-0-id': None,
'targets-0-last_name': None,
'targets-0-first_name': '',
'targets-0-id': '',
'targets-0-last_name': '',
'targets-INITIAL_FORMS': 0,
'targets-MAX_NUM_FORMS': 1000,
'targets-MIN_NUM_FORMS': 0,
Expand Down
6 changes: 2 additions & 4 deletions phishing/tests/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ def test_default_permission(self):
# delete not authorized
url = reverse('campaign_delete', args=(campaign.pk,))
response = self.client.get(url)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/accounts/login/?next=%s' % url)
self.assertEqual(response.status_code, 403)

# add not authorized
url = reverse('campaign_add')
campaign_infos['name'] = 'test 4'
response = self.client.post(url, campaign_infos)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/accounts/login/?next=%s' % url)
self.assertEqual(response.status_code, 403)

def test_permission(self):
permissions = ['view_emailtemplate', 'view_targetgroup']
Expand Down
2 changes: 2 additions & 0 deletions phishing/views/landing_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def landing_page(request, tracker_id):
landing_page=landing_page)

return HttpResponse(landing_page.html, content_type='text/html')
# TODO: It seems that django correctly handle foreignkey
# an this case is not possible anymore.
except Exception as e:
tracker_infos.raw = '%s: %s' % (e.__class__.__name__, e)
tracker_infos.save()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Basics
django==2.0.7
django==2.2.1
djangorestframework==3.9.4

# Templates
Expand Down

0 comments on commit 64db044

Please sign in to comment.