Ejemplo n.º 1
0
    def test_nested_censoring(self):
        example_handles = [
            ZipHandle(
                    ZipSource(
                            SMBCHandle(
                                    SMBCSource(
                                            "//SERVER/Resource",
                                            "username", driveletter="W"),
                                    "Confidential Documents.zip")),
                    "doc/Personal Information.docx"),
            FilteredHandle(
                    GzipSource(
                            SMBHandle(
                                    SMBSource(
                                            "//SERVER/usr", "username"),
                                    "share/doc/coreutils"
                                    "/changelog.Debian.gz")),
                    "changelog.Debian"),
        ]

        for handle in example_handles:
            with self.subTest(handle):
                self.assertIsNotNone(handle.source.handle.source._user)
                handle = handle.censor()
                self.assertIsNone(handle.source.handle.source._user)
Ejemplo n.º 2
0
    def test_smb_censoring(self):
        example_handles = [
            SMBHandle(
                    SMBSource(
                            "//SERVER/Resource", "username"),
                    "~ocument.docx"),
            SMBCHandle(
                    SMBCSource(
                            "//SERVER/Resource",
                            "username", "topsecret", "WORKGROUP8"),
                    "~ocument.docx"),
        ]

        for handle in example_handles:
            with self.subTest(handle):
                handle = handle.censor()

                self.assertIsNone(handle.source._domain)
                self.assertIsNone(handle.source._password)
                self.assertIsNone(handle.source._user)
Ejemplo n.º 3
0
 def make_engine2_source(self):
     return SMBCSource(
             self.url,
             user=self.authentication.username,
             password=self.authentication.get_password(),
             domain=self.authentication.domain)
Ejemplo n.º 4
0
    def test_sources(self):
        sources_and_urls = [
            (FilesystemSource("/usr"), "file:///usr"),
            (
                SMBSource("//10.0.0.30/Share$/Documents"),
                "smb://10.0.0.30/Share%24/Documents",
            ),
            (
                SMBSource("//10.0.0.30/Share$/Documents", "FaithfullA"),
                "smb://[email protected]/Share%24/Documents",
            ),
            (
                SMBSource(
                    "//10.0.0.30/Share$/Documents",
                    "FaithfullA",
                    "secretpassword",
                ),
                "smb://*****:*****@10.0.0.30/Share%24/Documents",
            ),
            (
                SMBSource(
                    "//10.0.0.30/Share$/Documents",
                    "FaithfullA",
                    "secretpassword",
                    "SYSGRP",
                ),
                "smb://SYSGRP;FaithfullA:[email protected]/Share%24"
                "/Documents",
            ),
            (
                SMBSource(
                    "//10.0.0.30/Share$/Documents",
                    "FaithfullA",
                    None,
                    "SYSGRP",
                ),
                "smb://SYSGRP;[email protected]/Share%24/Documents",
            ),
            (
                SMBCSource(
                    "//INT-SRV-01/Q$",
                    "FaithfullA",
                    None,
                    "SYSGRP",
                ),
                "smbc://SYSGRP;FaithfullA@INT-SRV-01/Q%24",
            ),
            (WebSource("http://www.example.com"), "http://www.example.com"),
            (
                SecureWebSource("https://www.example.com"),
                "https://www.example.com",
            ),
            (
                DataSource(b"This is a test", "text/plain"),
                "data:text/plain;base64,VGhpcyBpcyBhIHRlc3Q=",
            ),
        ]

        for source, url in sources_and_urls:
            with self.subTest(url):
                generated_url = source.to_url()
                self.assertEqual(url, generated_url)
Ejemplo n.º 5
0
    def test_json_round_trip(self):
        example_handles = [
            FilesystemHandle(FilesystemSource("/usr/share/common-licenses"),
                             "GPL-3"),
            DataHandle(DataSource(b"Test", "text/plain"), "file"),
            FilteredHandle(
                GzipSource(
                    FilesystemHandle(
                        FilesystemSource("/usr/share/doc/coreutils"),
                        "changelog.Debian.gz")), "changelog.Debian"),
            SMBHandle(SMBSource("//SERVER/Resource", "username"),
                      "~ocument.docx"),
            SMBCHandle(
                SMBCSource("//SERVER/Resource", "username", "topsecret",
                           "WORKGROUP8"), "~ocument.docx"),
            ZipHandle(
                ZipSource(
                    SMBCHandle(
                        SMBCSource("//SERVER/Resource",
                                   "username",
                                   driveletter="W"),
                        "Confidential Documents.zip")),
                "doc/Personal Information.docx"),
            WebHandle(WebSource("https://secret.data.invalid/"),
                      "lottery-numbers-for-next-week.txt"),
            TarHandle(
                TarSource(
                    FilesystemHandle(FilesystemSource("/home/user"),
                                     "Downloads/data.tar.gz")), "data0.txt"),
            MailPartHandle(
                MailSource(
                    EWSMailHandle(
                        EWSAccountSource(domain="cloudy.example",
                                         server=CLOUD,
                                         admin_user="******",
                                         admin_password="******",
                                         user="******"),
                        "SW5ib3hJRA==.TWVzc2dJRA==",
                        "Re: Castles in the sky")), "1/pictograph.jpeg",
                "image/jpeg"),
            PDFObjectHandle(
                PDFPageSource(
                    PDFPageHandle(
                        PDFSource(
                            FilesystemHandle(
                                FilesystemSource("/home/kiddw"
                                                 "/Documents"),
                                "1699 Gardiners trip/"
                                "treasure_map.pdf")), "10")),
                "X-marks-the-spot_000-0.png"),
            LibreOfficeObjectHandle(
                LibreOfficeSource(
                    FilesystemHandle(FilesystemSource("/media/user/USB STICK"),
                                     "What I Did On My Holidays.doc")),
                "What I Did On My Holidays.html")
        ]

        for handle in example_handles:
            with self.subTest(handle):
                json = handle.to_json_object()
                print(handle)
                print(json)
                self.assertEqual(handle, handle.from_json_object(json))
                print("--")
 def generate_sources(self):
     yield SMBCSource(self.url,
                      user=self.authentication.username,
                      password=self.authentication.get_password(),
                      domain=self.authentication.domain,
                      driveletter=self.alias)
Ejemplo n.º 7
0
from os2datascanner.engine2.model.derived.pdf import (PDFSource, PDFPageHandle,
                                                      PDFPageSource,
                                                      PDFObjectHandle)
from os2datascanner.engine2.model.derived.tar import TarSource, TarHandle
from os2datascanner.engine2.model.derived.zip import ZipSource, ZipHandle

example_handles = [
    FilesystemHandle(FilesystemSource("/usr/share/common-licenses"), "GPL-3"),
    DataHandle(DataSource(b"Test", "text/plain"), "file"),
    FilteredHandle(
        GzipSource(
            FilesystemHandle(FilesystemSource("/usr/share/doc/coreutils"),
                             "changelog.Debian.gz")), "changelog.Debian"),
    SMBHandle(SMBSource("//SERVER/Resource", "username"), "~ocument.docx"),
    SMBCHandle(
        SMBCSource("//SERVER/Resource", "username", "topsecret", "WORKGROUP8"),
        "~ocument.docx"),
    ZipHandle(
        ZipSource(
            SMBCHandle(
                SMBCSource("//SERVER/Resource", "username", driveletter="W"),
                "Confidential Documents.zip")),
        "doc/Personal Information.docx"),
    WebHandle(WebSource("https://secret.data.invalid/"),
              "lottery-numbers-for-next-week.txt"),
    TarHandle(
        TarSource(
            FilesystemHandle(FilesystemSource("/home/user"),
                             "Downloads/data.tar.gz")), "data0.txt"),
    MailPartHandle(
        MailSource(