|
import unittest
|
|
import mail
|
|
import os
|
|
|
|
mail_data = b'Delivered-To: ycolakoglu.bilisim@gmail.com\r\nReceived: by 2002:a4a:3b52:0:0:0:0:0 with SMTP id s79csp5499397oos;\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)\r\nX-Received: by 2002:a62:5284:: with SMTP id g126mr36248899pfb.95.1571116620441;\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)\r\nARC-Seal: i=1; a=rsa-sha256; t=1571116620; cv=none;\r\n d=google.com; s=arc-20160816;\r\n b=cpnYE9u9z+MntvqooyBpwsjspuZ1eIXZ0CbeDqM41EV6hYZhvVh94tWy55IyY/NxO/\r\n FaR81R1OC5eVt50vyEx1HHVSfF592GrexKhS5I54EDXF/4d8bbsruipRnw3HzSefmu5F\r\n 662POtR4sxcxAWfP0RSjecj8F6HzL/fPsf/zltB1E2mATNmvi55MJbyiXrkgSki7AsH2\r\n V0OTSSRbkei2a0jW0mFAf1aikYODSqxInejlIKB+L1fAWXVHrd/gw8Bb4HEFyzCBzx5O\r\n pX1qj4hCg2zZ9mq2gOyNjYpQiQPcRl4PeP6WS2FlDQHF1pvo/YIWIY/X9meRZU7OVhak\r\n pRKg==\r\nARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;\r\n h=to:from:subject:message-id:feedback-id:date:mime-version\r\n :dkim-signature;\r\n bh=T4/J1/5TDNqRq8UWUiIGuzPe7Zv+PrrvC6tmCrrt0i4=;\r\n b=F6ssVJAjMg4eWB+FOYSxC6Z3QJ5AksZBZiNyyQJaLwbQawF+ENaOIYzOD4zzUWcK9U\r\n NEhcv9onqo9FLH1jl4bQcNV7f2oSfrf3eQvzR56E8JSemz/eH32uN4rnM/H7Q+Q9A4WB\r\n QSQaEnS7OOuUbx7Vb53yxJ+0+tKogaK+Io5APQ0psLW2i5/ZraPYS4uLfAgsqwPGLSxa\r\n lK2aYOcpqNSPnye3Ie2jib+jL44sW1vMhlfr46MoF28guVPpj0ByWy/m62HDwjKdVUap\r\n HBcvw2oEFLV3aiqxsifMlbin3W0IR+ZppnZkxMWs+bmNn8YcOvpSqZ5bZR2hnyOW8+Iy\r\n Trqg==\r\nARC-Authentication-Results: i=1; mx.google.com;\r\n dkim=pass header.i=@accounts.google.com header.s=20161025 header.b=yqMoB78r;\r\n spf=pass (google.com: domain of 3s1alxqgtaiars-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3S1alXQgTAIArs-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com;\r\n dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=accounts.google.com\r\nReturn-Path: <3S1alXQgTAIArs-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com>\r\nReceived: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73])\r\n by mx.google.com with SMTPS id m6sor19968531pgp.62.2019.10.14.22.17.00\r\n for <ycolakoglu.bilisim@gmail.com>\r\n (Google Transport Security);\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)\r\nReceived-SPF: pass (google.com: domain of 3s1alxqgtaiars-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73;\r\nAuthentication-Results: mx.google.com;\r\n dkim=pass header.i=@accounts.google.com header.s=20161025 header.b=yqMoB78r;\r\n spf=pass (google.com: domain of 3s1alxqgtaiars-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3S1alXQgTAIArs-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com;\r\n dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=accounts.google.com\r\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n d=accounts.google.com; s=20161025;\r\n h=mime-version:date:feedback-id:message-id:subject:from:to;\r\n bh=T4/J1/5TDNqRq8UWUiIGuzPe7Zv+PrrvC6tmCrrt0i4=;\r\n b=yqMoB78ruEfTrMV0UsPvCuTrOs+o++szTk6Tnw//IhMJ/jj2TJvAWQvuUXaHVQKb7p\r\n 1FYqRrqOWj+zSTv/xeHz2W6SnVvA7ThoE1QVbZKBX2zSDe/yG6NImw7luFE/D3zbQ4Xk\r\n mMg2AM3Vvttkz8krt6omolVeJab7luTChU6mfojgF3lcrkHL3l5w9Q6eUY7q8vOP4SmN\r\n RevtIe3vZw6T/ozfjbyD8ptEZHqrJ93KHrot3Oe4wg0sDkhdLY6eYfQnQAKuDQKnpLA3\r\n gMdeu+jDikTfhIKu99WQqoY5Rer9XGVedtaaAZFJ+BB11iEkc939LmH5W6bHXeGF/itd\r\n ldog==\r\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n d=1e100.net; s=20161025;\r\n h=x-gm-message-state:mime-version:date:feedback-id:message-id:subject\r\n :from:to;\r\n bh=T4/J1/5TDNqRq8UWUiIGuzPe7Zv+PrrvC6tmCrrt0i4=;\r\n b=Ljo8+tiQogDE4ff31Fo4bq6GHH1n64neGOaFLYFqd/1dBBZhxLI+FJH9s+mYesbWoY\r\n 4/X77kHpwd5MDkmbkP/wsOdZe7MG9YpyucuWMJXRDWONkjl2PjTVLlNUJxLVFfj4P8WD\r\n fxF8iPKdjRiSxCuZXhU/FmpYtWacYjExUml3pjORuQe7wULCZgwV/u5oVqdqasfEW9aL\r\n J/X+uLDSpEPxUv9PnxtPWtiijna9RDv9qQXrQgyHFzDTQZcbs54thNDNdo/7CAVAAYdg\r\n b2eBlrLRZJ94EAVi1NmaPcoYzZnUwTyUqwJLk+RZ/Vb1vqm5HxCtjydH/Mg3iL5G3mPd\r\n w6Qw==\r\nX-Gm-Message-State: APjAAAXaHG4hlX5O1w5p2nhqKp2xe86KL7aWAPSRwV5ro4Gff5pjFZKO\r\n\tHarqGjLc4s3u2l5B7JdgXtrpTsEau1FO\r\nX-Google-Smtp-Source: APXvYqz9YuaVV0VswWE1Tw9wz0kTyq1vBWKS9mjYoZMSZ+ldB0Z3zcy3qvUeDD5k4rGpwGVdYXSUjFdKQTANgYi2rqOszg==\r\nMIME-Version: 1.0\r\nX-Received: by 2002:a63:8dc2:: with SMTP id z185mr36524384pgd.228.1571116619995;\r\n Mon, 14 Oct 2019 22:16:59 -0700 (PDT)\r\nDate: Tue, 15 Oct 2019 05:16:58 +0000 (GMT)\r\nX-Account-Notification-Type: 31-anexp#givab-fa--mdv2-fa--hsc-control_b--ivab-fa\r\nFeedback-ID: 31-anexp#givab-fa--mdv2-fa--hsc-control_b--ivab-fa:account-notifier\r\nX-Notifications: 4e28bdab0a800000\r\nMessage-ID: <L4gjhUVNWXEFO-3evyMtJw.0@notifications.google.com>\r\nSubject: Security alert\r\nFrom: Google <no-reply@accounts.google.com>\r\nTo: ycolakoglu.bilisim@gmail.com\r\nContent-Type: multipart/alternative; boundary="000000000000091c420594ec189c"\r\n\r\n--000000000000091c420594ec189c\r\nContent-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes\r\nContent-Transfer-Encoding: base64\r\n\r\nTmV3IGRldmljZSBzaWduZWQgaW4gdG8NCg0KDQp5Y29sYWtvZ2x1LmJpbGlzaW1AZ21haWwuY29t\r\nDQpZb3VyIEdvb2dsZSBBY2NvdW50IHdhcyBqdXN0IHNpZ25lZCBpbiB0byBmcm9tIGEgbmV3IExp\r\nbnV4IGRldmljZS4gWW91J3JlDQpnZXR0aW5nIHRoaXMgZW1haWwgdG8gbWFrZSBzdXJlIGl0IHdh\r\ncyB5b3UuDQpDaGVjayBhY3Rpdml0eQ0KPGh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbS9BY2Nv\r\ndW50Q2hvb3Nlcj9FbWFpbD15Y29sYWtvZ2x1LmJpbGlzaW1AZ21haWwuY29tJmNvbnRpbnVlPWh0\r\ndHBzOi8vbXlhY2NvdW50Lmdvb2dsZS5jb20vYWxlcnQvbnQvMTU3MTExNjYxODAwMD9yZm4lM0Qz\r\nMSUyNnJmbmMlM0QxJTI2ZWlkJTNELTg4NDgwODUyNzA4MzA0MDE5MDIlMjZldCUzRDAlMjZhbmV4\r\ncCUzRGdpdmFiLWZhLS1tZHYyLWZhLS1oc2MtY29udHJvbF9iLS1pdmFiLWZhPg0KWW91IHJlY2Vp\r\ndmVkIHRoaXMgZW1haWwgdG8gbGV0IHlvdSBrbm93IGFib3V0IGltcG9ydGFudCBjaGFuZ2VzIHRv\r\nIHlvdXINCkdvb2dsZSBBY2NvdW50IGFuZCBzZXJ2aWNlcy4NCsKpIDIwMTkgR29vZ2xlIExMQywg\r\nMTYwMCBBbXBoaXRoZWF0cmUgUGFya3dheSwgTW91bnRhaW4gVmlldywgQ0EgOTQwNDMsIFVTQQ0K\r\n--000000000000091c420594ec189c\r\nContent-Type: text/html; charset="UTF-8"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n<!DOCTYPE html><html lang=3Den><head><meta name=3Dformat-detection content=\r\n=3Demail=3Dno /><meta name=3Dformat-detection content=3Ddate=3Dno /><style =\r\nnonce=3DCTR93axv9AZ3+xXQxyqEqg>.awl a {color: #FFFFFF; text-decoration: non=\r\ne;} .abml a {color: #000000; font-family: Roboto-Medium,Helvetica,Arial,san=\r\ns-serif; font-weight: bold; text-decoration: none;} .adgl a {color: rgba(0,=\r\n 0, 0, 0.87); text-decoration: none;} .afal a {color: #b0b0b0; text-decorat=\r\nion: none;} @media screen and (min-width: 600px) {.v2sp {padding: 6px 30px =\r\n0px;} .v2rsp {padding: 0px 10px;}} @media screen and (min-width: 600px) {.m=\r\ndv2rw {padding: 40px 40px;}} </style><link href=3D//fonts.googleapis.com/cs=\r\ns?family=3DGoogle+Sans rel=3Dstylesheet type=3Dtext/css /></head><body styl=\r\ne=3D"margin: 0; padding: 0;" bgcolor=3D#FFFFFF><img src=3Dhttps://notificat=\r\nions.googleapis.com/email/t/AFG8qyXjIGpo_Y1ZYff2xW3vQ2HOZpBWtPdpNozopjTJPB4=\r\nGUU2n1gmZevFlABNybT3dXxRd8YFkPdPW5JOC7SzWWUriyrGbLKHO9tYdI7EKEve6fwSbpPlQby=\r\n-kongkTp5_kKIjcvM8aOLlM0zzNeejlq6ohIWAsCzpoyTQFG6J7FGIsOgN7kzqTZhiM4uGn1Z8r=\r\ntJBWFwKt6-wIFp7-daNd7nUKKoo87WXKpNbMo-KDXgXFBmhlfKUfutxjchI9yeYACtRVGOmP3-t=\r\nXV1eaME/a.gif width=3D1 height=3D1><table width=3D100% height=3D100% style=\r\n=3D"min-width: 348px;" border=3D0 cellspacing=3D0 cellpadding=3D0 lang=3Den=\r\n><tr height=3D32 style=3D"height: 32px;"><td></td></tr><tr align=3Dcenter><=\r\ntd><div itemscope itemtype=3D//schema.org/EmailMessage><div itemprop=3Dacti=\r\non itemscope itemtype=3D//schema.org/ViewAction><link itemprop=3Durl href=\r\n=3Dhttps://accounts.google.com/AccountChooser?Email=3Dycolakoglu.bilisim@gm=\r\nail.com&continue=3Dhttps://myaccount.google.com/alert/nt/1571116618000?=\r\nrfn%3D31%26rfnc%3D1%26eid%3D-8848085270830401902%26et%3D0%26anexp%3Dgivab-f=\r\na--mdv2-fa--hsc-control_b--ivab-fa /><meta itemprop=3Dname content=3D"Revie=\r\nw Activity" /></div></div><table border=3D0 cellspacing=3D0 cellpadding=3D0=\r\n style=3D"padding-bottom: 20px;max-width: 516px;min-width: 220px;"><tr><td =\r\nwidth=3D8 style=3D"width: 8px;"></td><td><div style=3D"border-style: solid;=\r\n border-width: thin; border-color:#dadce0; border-radius: 8px; padding: 40p=\r\nx 20px;" align=3Dcenter class=3Dmdv2rw><img width=3D75 height=3D24 src=3Dht=\r\ntps://www.gstatic.com/accountalerts/email/googlelogo_color_188x64dp.png sty=\r\nle=3D"width: 75px; height: 24px; margin-bottom: 16px;"><div style=3D"font-f=\r\namily: 'Google Sans',Roboto,RobotoDraft,Helvetica,Arial,sans-serif;=\r\nborder-bottom: thin solid #dadce0; color: rgba(0,0,0,0.87); line-height: 32=\r\npx; padding-bottom: 24px;text-align: center; word-break: break-word;"><div =\r\nstyle=3D"font-size: 24px;">New device signed in to</div><table align=\r\n=3Dcenter style=3Dmargin-top:8px;><tr style=3D"line-height: normal;"><td al=\r\nign=3Dright style=3Dpadding-right:8px;><img width=3D20 height=3D20 style=3D=\r\n"width: 20px; height: 20px; vertical-align: sub; border-radius: 50%;;" src=\r\n=3Dhttps://lh3.googleusercontent.com/a-/AAuE7mBkqTlSeunlVtGmIqxUBe5FImqBOeS=\r\nIMhi_b4A7=3Ds96></td><td><a style=3D"font-family: 'Google Sans',Rob=\r\noto,RobotoDraft,Helvetica,Arial,sans-serif;color: rgba(0,0,0,0.87); font-si=\r\nze: 14px; line-height: 20px;">ycolakoglu.bilisim@gmail.com</a></td></tr></t=\r\nable></div><div style=3D"font-family: Roboto-Regular,Helvetica,Arial,sans-s=\r\nerif; font-size: 14px; color: rgba(0,0,0,0.87); line-height: 20px;padding-t=\r\nop: 20px; text-align: center;">Your Google Account was just signed in to fr=\r\nom a new Linux device. You\'re getting this email to make sure it was you.<d=\r\niv style=3D"padding-top: 32px;text-align: center;"><a href=3Dhttps://accoun=\r\nts.google.com/AccountChooser?Email=3Dycolakoglu.bilisim@gmail.com&conti=\r\nnue=3Dhttps://myaccount.google.com/alert/nt/1571116618000?rfn%3D31%26rfnc%3=\r\nD1%26eid%3D-8848085270830401902%26et%3D0%26anexp%3Dgivab-fa--mdv2-fa--hsc-c=\r\nontrol_b--ivab-fa target=3D_blank style=3D"font-family: 'Google Sans=\r\n9;,Roboto,RobotoDraft,Helvetica,Arial,sans-serif; line-height: 16px; color:=\r\n #ffffff; font-weight: 400; text-decoration: none;font-size: 14px;display:i=\r\nnline-block;padding: 10px 24px;background-color: #4184F3; border-radius: 5p=\r\nx; min-width: 90px;">Check activity</a></div></div></div><div style=3D"text=\r\n-align: left;"><div style=3D"font-family: Roboto-Regular,Helvetica,Arial,sa=\r\nns-serif;color: rgba(0,0,0,0.54);font-size: 11px; line-height: 18px; paddin=\r\ng-top: 12px; text-align: center;"><div>You received this email to let you k=\r\nnow about important changes to your Google Account and services.</div><div =\r\nstyle=3D"direction: ltr;">© 2019 Google LLC, <a class=3Dafal style=3D"=\r\nfont-family: Roboto-Regular,Helvetica,Arial,sans-serif;color: rgba(0,0,0,0.=\r\n54);font-size: 11px; line-height: 18px; padding-top: 12px; text-align: cent=\r\ner;">1600 Amphitheatre Parkway, Mountain View, CA 94043, USA</a></div></div=\r\n></div></td><td width=3D8 style=3D"width: 8px;"></td></tr></table></td></tr=\r\n><tr height=3D32 style=3D"height: 32px;"><td></td></tr></table></body></htm=\r\nl>\r\n--000000000000091c420594ec189c--\r\n'
|
|
|
|
|
|
class MailTest(unittest.TestCase):
|
|
def test_from(self):
|
|
mail_obj = mail.Mail(mail_data)
|
|
self.assertEqual(mail_obj.header_data["From"], "Google <no-reply@accounts.google.com>")
|
|
|
|
def test_received(self):
|
|
mail_obj = mail.Mail(mail_data)
|
|
self.assertEqual(mail_obj.header_data["Received"], 'by 2002:a4a:3b52:0:0:0:0:0 with SMTP id s79csp5499397oos;\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)')
|
|
|
|
def test_date(self):
|
|
mail_obj = mail.Mail(mail_data)
|
|
self.assertEqual(mail_obj.header_data["Date"], "Tue, 15 Oct 2019 05:16:58 +0000 (GMT)")
|
|
|
|
def test_mail_blacklist(self):
|
|
mail_obj = mail.Mail(mail_data.replace(b"2002:a4a:3b52:0:0:0:0:0", b"unittest.malicious.com"))
|
|
mail_obj.DOMAIN_COEFFICIENT = 2
|
|
mail_obj.DOMAIN_THRESHOLD = 5
|
|
mail_obj.check_blacklisted()
|
|
self.assertTrue(mail_obj._spam)
|
|
|
|
mail_obj = mail.Mail(mail_data.replace(b"no-reply@accounts.google.com", b"utest@malicious.com"))
|
|
mail_obj.MAIL_COEFFICIENT = 2
|
|
mail_obj.MAIL_THRESHOLD = 5
|
|
mail_obj.check_blacklisted()
|
|
self.assertTrue(mail_obj._spam)
|
|
|
|
def test_domain_blacklist(self):
|
|
mail_obj = mail.Mail(mail_data)
|
|
mail_obj.DOMAIN_COEFFICIENT = 2
|
|
mail_obj.DOMAIN_THRESHOLD = 5
|
|
mail_obj.check_spam()
|
|
self.assertTrue(mail_obj._spam)
|
|
|
|
|
|
class MailBoxTest(unittest.TestCase):
|
|
|
|
def test_mail_walk(self):
|
|
mail_dir = os.path.join(os.getcwd(), "mails/<domain>/<user>")
|
|
mailbox_obj = mail.MailBox("ycolakoglu.bilisim@gmail.com", "totallysecurepass", "imap.google.com", 993)
|
|
self.assertEqual(list(mailbox_obj.mails.keys()), ["mail_example"])
|
|
|
|
def test_mail_parse(self):
|
|
mail_dir = os.path.join(os.getcwd(), "mails/<domain>/<user>")
|
|
mailbox_obj = mail.MailBox("ycolakoglu.bilisim@gmail.com", "totallysecurepass", "imap.google.com", 993)
|
|
self.assertEqual(mailbox_obj.mails["mail_example"][0].message, "Hello boi this is a test\n")
|
|
|
|
def test_xss_check(self):
|
|
mail_dir = os.path.join(os.getcwd(), "mails/<domain>/<user>")
|
|
mailbox_obj = mail.MailBox("ycolakoglu.bilisim@gmail.com", "totallysecurepass", "imap.google.com", 993)
|
|
mailbox_obj.check_spam()
|
|
self.assertEqual()
|
|
|
|
if __name__ == '__main__':
|
|
MailTest.run()
|
|
MailBoxTest.run()
|