示例#1
0
    def test_manage_account_delete(self):
        account = Account()
        account.username = "******"
        account.endpoint__dropbox_enabled = True

        new_token = PushToken()
        new_token.account = "michael"
        new_token.token = "token1"
        new_token.admin = True

        storage = Storage()
        storage.id = "id1"
        storage.account = "michael"
        storage.path = "/"
        storage.endpoint__amazon_s3_access_key_id = "endpoint__amazon_s3_access_key_id"
        storage.endpoint__amazon_s3_access_secret_key = "endpoint__amazon_s3_access_secret_key"
        storage.endpoint__dropbox_access_token = "endpoint__dropbox_access_token"
        storage.endpoint__dropbox_user_id = "endpoint__dropbox_user_id"
        storage.store_type = "dropbox"

        self.persist([account, new_token, storage])

        self.app.delete(
            "/manage/account/storage?token=token1", data=json.dumps({"id": "id1"})
        )

        rv = self.app.get(
            "/manage/account/storage?token=token1",
        )

        assert len(json.loads(rv.data)["storage"]) == 0
示例#2
0
    def test_manage_account_storage_save(self):
        account = Account()
        account.username = "******"
        account.endpoint__dropbox_enabled = True

        new_token = PushToken()
        new_token.account = "michael"
        new_token.token = "token1"
        new_token.admin = True

        storage = Storage()
        storage.id = "id1"
        storage.account = "michael"
        storage.path = ""
        storage.endpoint__amazon_s3_access_key_id = ""
        storage.endpoint__amazon_s3_access_secret_key = ""
        storage.endpoint__dropbox_access_token = ""
        storage.endpoint__dropbox_user_id = ""
        storage.store_type = ""

        self.persist([account, new_token, storage])

        rv = self.app.post(
            "/manage/account/storage?token=token1",
            data=json.dumps({
                "id": "id1",
                "path": "/path",
                "store_type": "dropbox"
            })
        )

        rv = self.app.get(
            "/manage/account/storage?token=token1",
        )

        assert json.loads(rv.data) == {
            "storage": [
                {
                    "account": "michael",
                    "endpoint__amazon_s3_access_key_id": "",
                    "endpoint__amazon_s3_access_secret_key": "",
                    "endpoint__dropbox_access_token": "",
                    "endpoint__dropbox_user_id": "",
                    "id": "id1",
                    "path": "/path",
                    "store_type": "dropbox"
                }
            ]
        }
示例#3
0
def manage_storage_put():
    token = request.args.get("token")
    token_object = flask.g.db_session.query(PushToken).filter(
        PushToken.token == token).scalar()
    if not token_object or not token_object.admin:
        return flask.jsonify(err="Token was not valid"), 403

    entry = Storage()
    entry.id = str(uuid.uuid4())
    entry.path = "/"
    entry.permissions = "rw"
    entry.account = token_object.account
    flask.g.db_session.add(entry)
    return flask.jsonify({})
示例#4
0
    def test__upload_file__dropbox__temp_user__wrong_permissions_path(
            self, __upload_dropbox):
        account = Account()
        account.username = "******"
        account.endpoint__dropbox_enabled = True

        credentials = TempCredentials()
        credentials.account = "michael"
        credentials.username = "******"
        credentials.permissions_mode = "w"
        credentials.permissions_path = "/dudes"

        new_token = PushToken()
        new_token.account = "michael"
        new_token.token = "token1"
        new_token.admin = False
        new_token.authenticated_user = "******"

        storage = Storage()
        storage.id = "id1"
        storage.account = "michael"
        storage.path = "/"
        storage.endpoint__amazon_s3_access_key_id = ""
        storage.endpoint__amazon_s3_access_secret_key = ""
        storage.endpoint__dropbox_access_token = ""
        storage.endpoint__dropbox_user_id = ""
        storage.store_type = "dropbox"
        storage.permissions = "rw"

        self.persist([account, new_token, storage, credentials])

        resp = self.app.post('/push/upload/token1',
                             data={
                                 'file': (StringIO('my file contents'),
                                          'hello world.txt'),
                                 'path':
                                 "/hello world.txt"
                             })

        assert resp.status_code == 403
        assert len(self.session.query(File).all()) == 0
        assert __upload_dropbox.called == 0
示例#5
0
    def test__upload_file__dropbox_nopath(self, __upload_dropbox):
        account = Account()
        account.username = "******"
        account.endpoint__dropbox_enabled = True

        new_token = PushToken()
        new_token.account = "michael"
        new_token.token = "token1"
        new_token.admin = True

        storage = Storage()
        storage.id = "id1"
        storage.account = "michael"
        storage.path = "/"
        storage.endpoint__amazon_s3_access_key_id = ""
        storage.endpoint__amazon_s3_access_secret_key = ""
        storage.endpoint__dropbox_access_token = ""
        storage.endpoint__dropbox_user_id = ""
        storage.store_type = "dropbox"
        storage.permissions = "rw"

        self.persist([account, new_token, storage])

        resp = self.app.post('/push/upload/token1',
                             data={
                                 'file': (StringIO('my file contents'),
                                          'hello world.txt'),
                                 'path':
                                 "/hello world.txt"
                             })

        assert resp.status_code == 200
        assert len(self.session.query(File).all()) == 1
        assert __upload_dropbox.called == 1
        __upload_dropbox.assert_called_with(mock.ANY, mock.ANY,
                                            '/hello world.txt')
示例#6
0
    def test__upload_file__choose_path(self, __upload_s3, __upload_dropbox):
        account = Account()
        account.username = "******"
        account.endpoint__dropbox_enabled = True

        new_token = PushToken()
        new_token.account = "michael"
        new_token.token = "token1"
        new_token.admin = True

        storage = Storage()
        storage.id = "id1"
        storage.account = "michael"
        storage.path = "/dropbox/path"
        storage.store_type = "dropbox"
        storage.permissions = "rw"

        storage2 = Storage()
        storage2.id = "id2"
        storage2.account = "michael"
        storage2.path = "/s3/path"
        storage2.store_type = "s3"
        storage2.permissions = "rw"

        storage3 = Storage()
        storage3.id = "id3"
        storage3.account = "michael"
        storage3.path = "/"
        storage3.store_type = "dropbox"
        storage3.permissions = "rw"

        self.persist([account, new_token, storage, storage2, storage3])

        resp = self.app.post('/push/upload/token1',
                             data={
                                 'file': (StringIO('my file contents'),
                                          'hello world.txt'),
                                 'path':
                                 "/s3/path/hello world.txt"
                             })

        assert resp.status_code == 200
        assert len(self.session.query(File).all()) == 1
        assert __upload_s3.called == 1
        __upload_s3.assert_called_with(mock.ANY, mock.ANY, '/hello world.txt')