Exemplo n.º 1
0
    def set_up(test_settings):
        """Create GUI with given settings"""
        # Create our test file
        testfile = open("/tmp/test.txt", "w")
        testfile.write("onionshare")
        testfile.close()

        # Create a test dir and files
        if not os.path.exists("/tmp/testdir"):
            testdir = os.mkdir("/tmp/testdir")
        testfile = open("/tmp/testdir/test.txt", "w")
        testfile.write("onionshare")
        testfile.close()

        common = Common()
        common.settings = Settings(common)
        common.define_css()
        strings.load_strings(common)

        # Get all of the settings in test_settings
        test_settings["connection_type"] = "automatic"
        test_settings["data_dir"] = "/tmp/OnionShare"
        for key, val in common.settings.default_settings.items():
            if key not in test_settings:
                test_settings[key] = val

        # Start the Onion
        testonion = Onion(common)
        global qtapp
        qtapp = Application(common)
        app = OnionShare(common, testonion, False, 0)

        web = Web(common, False, False)
        open("/tmp/settings.json", "w").write(json.dumps(test_settings))

        gui = OnionShareGui(
            common,
            testonion,
            qtapp,
            app,
            ["/tmp/test.txt", "/tmp/testdir"],
            "/tmp/settings.json",
            False,
        )
        return gui
Exemplo n.º 2
0
    def setUpClass(cls):
        common = Common(verbose=True)

        # Delete any old test data that might exist
        shutil.rmtree(common.build_data_dir(), ignore_errors=True)

        qtapp = Application(common)
        common.gui = GuiCommon(common, qtapp, local_only=True)
        cls.gui = MainWindow(common, filenames=None)
        cls.gui.qtapp = qtapp

        # Create some random files to test with
        cls.tmpdir = tempfile.TemporaryDirectory()
        cls.tmpfiles = []
        for _ in range(10):
            filename = os.path.join(cls.tmpdir.name, f"{secrets.token_hex(4)}.txt")
            with open(filename, "w") as file:
                file.write(secrets.token_hex(10))
            cls.tmpfiles.append(filename)

        # A file called "test.txt"
        cls.tmpfile_test = os.path.join(cls.tmpdir.name, "test.txt")
        with open(cls.tmpfile_test, "w") as file:
            file.write("onionshare")

        # A file called "test2.txt"
        cls.tmpfile_test2 = os.path.join(cls.tmpdir.name, "test2.txt")
        with open(cls.tmpfile_test2, "w") as file:
            file.write("onionshare2")

        # A file called "index.html"
        cls.tmpfile_index_html = os.path.join(cls.tmpdir.name, "index.html")
        with open(cls.tmpfile_index_html, "w") as file:
            file.write(
                "<html><body><p>This is a test website hosted by OnionShare</p></body></html>"
            )

        # A large file
        size = 1024 * 1024 * 155
        cls.tmpfile_large = os.path.join(cls.tmpdir.name, "large_file")
        with open(cls.tmpfile_large, "wb") as fout:
            fout.write(os.urandom(size))
Exemplo n.º 3
0
    def set_up(test_settings):
        '''Create GUI with given settings'''
        # Create our test file
        testfile = open('/tmp/test.txt', 'w')
        testfile.write('onionshare')
        testfile.close()

        # Create a test dir and files
        if not os.path.exists('/tmp/testdir'):
            testdir = os.mkdir('/tmp/testdir')
        testfile = open('/tmp/testdir/test.txt', 'w')
        testfile.write('onionshare')
        testfile.close()

        common = Common()
        common.settings = Settings(common)
        common.define_css()
        strings.load_strings(common)

        # Get all of the settings in test_settings
        test_settings['connection_type'] = 'automatic'
        test_settings['data_dir'] = '/tmp/OnionShare'
        for key, val in common.settings.default_settings.items():
            if key not in test_settings:
                test_settings[key] = val

        # Start the Onion
        testonion = Onion(common)
        global qtapp
        qtapp = Application(common)
        app = OnionShare(common, testonion, False, 0)

        web = Web(common, False, False)
        open('/tmp/settings.json', 'w').write(json.dumps(test_settings))

        gui = OnionShareGui(common, testonion, qtapp, app,
                            ['/tmp/test.txt', '/tmp/testdir'],
                            '/tmp/settings.json', False)
        return gui
Exemplo n.º 4
0
    def set_up(test_settings):
        """Create GUI with given settings"""
        # Create our test file
        testfile = open("/tmp/index.html", "w")
        testfile.write(
            "<html><body><p>This is a test website hosted by OnionShare</p></body></html>"
        )
        testfile.close()

        common = Common()
        common.settings = Settings(common)
        common.define_css()
        strings.load_strings(common)

        # Get all of the settings in test_settings
        test_settings["data_dir"] = "/tmp/OnionShare"
        for key, val in common.settings.default_settings.items():
            if key not in test_settings:
                test_settings[key] = val

        # Start the Onion
        testonion = Onion(common)
        global qtapp
        qtapp = Application(common)
        app = OnionShare(common, testonion, True, 0)

        web = Web(common, False, True)
        open("/tmp/settings.json", "w").write(json.dumps(test_settings))

        gui = OnionShareGui(
            common,
            testonion,
            qtapp,
            app,
            ["/tmp/index.html"],
            "/tmp/settings.json",
            True,
        )
        return gui
Exemplo n.º 5
0
    def set_up():
        '''Create the GUI'''

        # Default settings for the settings GUI tests
        test_settings = {
            "no_bridges":
            False,
            "tor_bridges_use_custom_bridges":
            "Bridge 1.2.3.4:56 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 5.6.7.8:910 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 11.12.13.14:1516 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n",
        }

        # Create our test file
        testfile = open('/tmp/test.txt', 'w')
        testfile.write('onionshare')
        testfile.close()

        common = Common()
        common.settings = Settings(common)
        common.define_css()
        strings.load_strings(common)

        # Start the Onion
        testonion = Onion(common)
        global qtapp
        qtapp = Application(common)
        app = OnionShare(common, testonion, True, 0)

        for key, val in common.settings.default_settings.items():
            if key not in test_settings:
                test_settings[key] = val

        open('/tmp/settings.json', 'w').write(json.dumps(test_settings))

        gui = SettingsDialog(common, testonion, qtapp, '/tmp/settings.json',
                             True)
        return gui