Skip to content

Commit 541f59a

Browse files
Merge pull request #53 from CybercentreCanada/AL-2646
Modify APIs to support passing submission profile names
2 parents bcaa483 + 79ce303 commit 541f59a

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

assemblyline_client/v4_client/module/ingest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, connection):
1111
self._connection = connection
1212

1313
def __call__(self, fh=None, path=None, content=None, url=None, sha256=None, fname=None, params=None, metadata=None,
14-
alert=False, nq=None, nt=None, ingest_type='AL_CLIENT'):
14+
alert=False, nq=None, nt=None, ingest_type='AL_CLIENT', submission_profile=None):
1515
"""\
1616
Submit a file to the ingestion queue.
1717
@@ -30,6 +30,7 @@ def __call__(self, fh=None, path=None, content=None, url=None, sha256=None, fnam
3030
nt : Notification threshold. (int)
3131
params : Additional submission parameters. (dict)
3232
ingest_type: Ingestion type, one word to describe how the data is ingested. Default: AL_CLIENT (string)
33+
submission_profile : Submission profile name
3334
3435
If content is provided, the path is used as metadata only.
3536
"""
@@ -87,7 +88,8 @@ def __call__(self, fh=None, path=None, content=None, url=None, sha256=None, fnam
8788
request['notification_threshold'] = int(nt)
8889
if params:
8990
request['params'] = params
90-
91+
if submission_profile:
92+
request['submission_profile'] = submission_profile
9193
if files:
9294
data = {'json': dumps(request)}
9395
headers = {'content-type': None}

assemblyline_client/v4_client/module/submit.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Submit(object):
1010
def __init__(self, connection):
1111
self._connection = connection
1212

13-
def __call__(self, fh=None, path=None, content=None, url=None, sha256=None, fname=None, params=None, metadata=None):
13+
def __call__(self, fh=None, path=None, content=None, url=None, sha256=None, fname=None, params=None, metadata=None, submission_profile=None):
1414
"""\
1515
Submit a file to be dispatched.
1616
@@ -22,9 +22,10 @@ def __call__(self, fh=None, path=None, content=None, url=None, sha256=None, fnam
2222
url : Url to scan (string)
2323
2424
Optional
25-
fname : Name of the file to scan
26-
metadata : Metadata to include with submission. (dict)
27-
params : Additional submission parameters. (dict)
25+
fname : Name of the file to scan
26+
metadata : Metadata to include with submission. (dict)
27+
params : Additional submission parameters. (dict)
28+
submission_profile : Submission profile name
2829
2930
If content is provided, the path is used as metadata only.
3031
"""
@@ -73,6 +74,9 @@ def __call__(self, fh=None, path=None, content=None, url=None, sha256=None, fnam
7374
if metadata:
7475
request['metadata'] = metadata
7576

77+
if submission_profile:
78+
request['submission_profile'] = submission_profile
79+
7680
if files:
7781
data = {'json': dumps(request)}
7882
headers = {'content-type': None}

test/conftest.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
2-
import pytest
32

3+
import pytest
44

55
UI_HOST = os.getenv('UI_HOST', "https://localhost:443")
66

@@ -24,13 +24,13 @@ def skip_or_fail(message):
2424

2525

2626
try:
27-
from assemblyline.common.security import get_random_password, get_password_hash
28-
from assemblyline.datastore.store import ESStore
29-
from assemblyline.datastore.helper import AssemblylineDatastore
30-
from assemblyline.common.uid import get_random_id
31-
3227
from assemblyline_client import get_client
28+
3329
from assemblyline.common import forge
30+
from assemblyline.common.security import get_password_hash, get_random_password
31+
from assemblyline.common.uid import get_random_id
32+
from assemblyline.datastore.helper import AssemblylineDatastore
33+
from assemblyline.datastore.store import ESStore
3434
from assemblyline.odm import random_data
3535

3636
config = forge.get_config()
@@ -80,15 +80,8 @@ def datastore(datastore_connection, filestore):
8080
random_data.wipe_workflows(ds)
8181

8282
@pytest.fixture(scope="module")
83-
def client(datastore):
84-
user = datastore.user.get('admin')
85-
random_pass = get_random_password(length=48)
86-
key_name = "key_%s" % get_random_id().lower()
87-
user.apikeys[key_name] = {"password": get_password_hash(random_pass), "acl": ["R", "W", "E"]}
88-
datastore.user.save('admin', user)
89-
api_key = "%s:%s" % (key_name, random_pass)
90-
91-
c = get_client(UI_HOST, apikey=('admin', api_key), verify=False, retries=1)
83+
def client():
84+
c = get_client(UI_HOST, auth=('admin', 'admin'), verify=False, retries=1)
9285
return c
9386

9487
except (ImportError, ModuleNotFoundError):

test/test_user.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import pytest
21
import random
32

3+
import pytest
44
from assemblyline_client.v4_client.common.utils import ClientError
55

66
try:
7-
from assemblyline.odm.models.user_favorites import Favorite
7+
from utils import random_id_from_collection
8+
89
from assemblyline.odm.models.user import User
10+
from assemblyline.odm.models.user_favorites import Favorite
911
from assemblyline.odm.random_data import random_model_obj
10-
11-
from utils import random_id_from_collection
1212
except ImportError:
1313
import sys
1414
if sys.version_info < (3, 0):
@@ -143,14 +143,15 @@ def test_settings(datastore, client):
143143
assert {'classification', 'download_encoding', 'priority', 'ttl'}.issubset(set(settings.keys()))
144144

145145
# Test updating settings
146-
new_desc = 'NEW_DEFAULT_DESCRIPTION'
147-
settings['description'] = new_desc
146+
new_password = "zippy"
147+
settings['default_zip_password'] = new_password
148148

149149
res = client.user.settings.update(user_id, settings)
150150
assert res['success']
151151

152152
# Validate changes were applied
153-
assert new_desc == datastore.user_settings.get(user_id, as_obj=False)['description']
153+
datastore.user_settings.commit()
154+
assert new_password == datastore.user_settings.get(user_id, as_obj=False)['default_zip_password']
154155

155156

156157
def test_submission_params(datastore, client):

0 commit comments

Comments
 (0)