Beispiel #1
0
def test_broken_if_no_gpg_home(gpg_blob, monkeypatch):
    monkeypatch.setattr(pgp, 'gpghome', Path('/tmp/no-such-gpghome'))

    with pytest.raises(tasks.ShaormaBroken) as e:
        email.parse(gpg_blob)

    assert e.value.reason == 'gpg_not_configured'
Beispiel #2
0
def test_broken_if_no_gpg_home(gpg_blob, monkeypatch):
    monkeypatch.setattr(
        'snoop.data.collections.Collection.gpghome_path',
        Path('/tmp/no-such-gpghome'),
    )

    with pytest.raises(tasks.SnoopTaskBroken) as e:
        email.parse(gpg_blob)

    assert e.value.reason == 'gpg_not_configured'
Beispiel #3
0
def test_email_header_parsing():
    eml_blob = models.Blob.create_from_file(EML)
    eml_data_blob = email.parse(eml_blob)
    with eml_data_blob.open() as f:
        content = json.load(f)
    assert content['headers']['Subject'] == [
        'Attachments have long file names.'
    ]
Beispiel #4
0
def test_broken_header():
    eml = DATA / 'eml-10-broken-header/broken-subject.eml'
    blob = models.Blob.create_from_file(eml)
    result = email.parse(blob)
    with result.open(encoding='utf8') as f:
        data = json.load(f)
    assert data['headers']['Subject'] == [
        ("A\ufffd\ufffda crap\ufffd\ufffd "
         "headerul fle\ufffd\ufffdc\ufffd\ufffdit")
    ]
Beispiel #5
0
def test_decrypted_data(gpg_blob):
    parsed_blob = email.parse(gpg_blob)

    with parsed_blob.open(encoding='utf8') as f:
        data = json.load(f)

    assert data['headers']['Subject'][0] == "Fwd: test email"
    assert data['headers']['Date'][0] == 'Wed, 10 Aug 2016 15:00:00 -0000'

    assert data['parts'][0]['pgp']
    text = data['parts'][0]['text']
    assert "This is GPG v1 speaking!" in text
    assert "Hello from the other side!" in text
    assert "Sent from my Android piece of !@#%." in text

    word_doc_pk = data['parts'][3]['attachment']['blob_pk']
    word_doc = models.Blob.objects.get(pk=word_doc_pk)
    assert word_doc.mime_type == 'application/msword'
Beispiel #6
0
def test_broken_if_no_gpg_home(gpg_blob):
    with pytest.raises(tasks.ShaormaBroken) as e:
        email.parse(gpg_blob)

    assert e.value.reason == 'gpg_not_configured'