Пример #1
0
 def setUp(self) -> None:
     with contextlib.suppress(FileNotFoundError):
         os.remove(test_dir + config.BLOOM_FILE)
         os.remove(test_dir + config.STORAGE_DB)
         os.remove(test_dir + config.KEYSERVER_DB)
     # Flask apps
     self.str_app = storage_server.create_app(self.test_config,
                                              logging_level=loglvl)
     self.key_app = key_server.create_app(self.test_config,
                                          logging_level=loglvl)
     Session.register('https://localhost:5000', self.key_app)
     Session.register('https://localhost:5001', self.str_app)
     # Create Fake users for Key Server
     with self.key_app.app_context():
         c = Client(username=self.user, password="******")
         p = Owner(username=self.provider, password="******")
         user_db.session.add(c)
         user_db.session.add(p)
         user_db.session.commit()
     # Create Fake users for Storage Server
     with self.str_app.app_context():
         c = Client(username=self.user, password="******")
         p = Owner(username=self.provider, password="******")
         user_db.session.add(c)
         user_db.session.add(p)
         user_db.session.commit()
def test_it_forwards_base_url(app):
    base_url = 'https://awesome-app'
    Session.register('https://awesome-app', app, base_url)
    session = Session()

    res = session.get('https://awesome-app/location', headers={'Location': '/hello_world'})
    assert res.headers['Location'] == 'https://awesome-app/location'
def test_it_can_patch_requests_with_base_url(app):
    from requests_flask_adapter.helpers import patch_requests
    base_url = 'http://patched_app'
    patch_requests([(base_url, app, base_url)])
    from requests import Session
    res = Session().get('http://patched_app/location')
    assert res.headers['Location'] == '{}/location'.format(base_url)
Пример #4
0
    def test_client_integrity_bpe(self):
        # Full Integrity Test including flask
        self.c = client.Client(self.user)
        self.c.set_password(self.password)
        self.c.metric = "offset-0.1"
        # Redirect requests to flask
        target = self.target
        # Server Records:
        matches: List[Record] = self.matches
        str_backend = StorageServer(test_dir)
        with self.str_app.app_context():
            for m in matches:
                str_backend.store_record(
                    to_base64(m.get_long_hash()),
                    json.dumps(m.get_encrypted_record(self.enc_keys[0])),
                    'OwnerA')
        # PSI Matches
        psi_matches = []
        for m in matches:
            psi_matches.append(m.get_psi_index())

        s = Session(True)
        with patch("requests.get", s.get), \
                patch("requests.post", s.post), \
                patch.object(self.c, "_receive_ots",
                             Mock(return_value=self.enc_keys_int[:3])):
            res = self.c.full_retrieve(target)
        # Set hash key for comparison
        for r in res:
            r.set_hash_key(self.hash_key)
        # Compare without order
        for m in matches:
            self.assertIn(m, res)
        for r in res:
            self.assertIn(r, matches)
Пример #5
0
    def test_data_provider_int(self):
        # Full integrity Test including flask
        self.dp = data_provider.DataProvider(self.provider)
        self.dp.set_password(self.password)
        str_backend = StorageServer(test_dir)
        with self.str_app.app_context():
            for r in self.sr:
                # check that bloom filter is empty
                b = str_backend.bloom
                self.assertNotIn(to_base64(r.get_long_hash()), b)
            # Check that DB empty
            res = str_backend.batch_get_records(
                [to_base64(r.get_long_hash()) for r in self.sr], "client")
        # Decrypt
        result = [
            Record.from_ciphertext(json.loads(r), self.enc_keys[0])
            for h, r in res
        ]
        self.assertEqual([], result)

        s = Session(True)
        with patch("requests.get", s.get), \
             patch("requests.post", s.post), \
             patch.object(self.dp, "_receive_ots",
                          Mock(return_value=self.enc_keys_int[:len(self.sr)])):
            self.dp.store_records(self.sr)

        str_backend = StorageServer(test_dir)
        with self.str_app.app_context():
            for r in self.sr:
                # check that records are in bloom filter
                b = str_backend.bloom
                self.assertIn(to_base64(r.get_long_hash()), b)
            # Check records in db
            res = str_backend.batch_get_records(
                [to_base64(r.get_long_hash()) for r in self.sr], "client")
        # Decrypt
        result = [
            Record.from_ciphertext(json.loads(r), self.enc_keys[0])
            for h, r in res
        ]
        for m in self.sr:
            self.assertIn(m, result)
        for r in result:
            self.assertIn(r, self.sr)
Пример #6
0
 def client(app):
     Session.register('http://app', app)
     return Session()
def session(app):
    Session.register('http://app', app)
    return Session()
def test_it_can_patch_requests(app):
    from requests_flask_adapter.helpers import patch_requests
    patch_requests([('http://patched_app', app)])
    from requests import Session
    res = Session().get('http://patched_app/echo')
    assert res.json()['path'] == 'echo'
Пример #9
0
def session(webapp):
    Session.register(API_ROOT, webapp)
    return Session()