summaryrefslogtreecommitdiff
path: root/yarns
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-11-16 21:36:04 +0200
committerLars Wirzenius <liw@liw.fi>2018-11-16 21:36:04 +0200
commit6d621d3a51ba68f0a436d5c5b27ace6cb2825f50 (patch)
tree6817d537d5475ccd3b8d888e20cdc51bd357f33e /yarns
parentd30c7d5dac5891ad86a3491e198cb384e466932e (diff)
downloadmuck-poc-6d621d3a51ba68f0a436d5c5b27ace6cb2825f50.tar.gz
Change: allow super users to impersonate other users
Diffstat (limited to 'yarns')
-rw-r--r--yarns/200-super.yarn43
-rw-r--r--yarns/900-implements.yarn15
-rw-r--r--yarns/lib.py3
3 files changed, 61 insertions, 0 deletions
diff --git a/yarns/200-super.yarn b/yarns/200-super.yarn
new file mode 100644
index 0000000..d07e451
--- /dev/null
+++ b/yarns/200-super.yarn
@@ -0,0 +1,43 @@
+# A happy path scenario
+
+This scenario does some basic resource management via the Muck API.
+
+ SCENARIO super user
+
+Start Muck. This also sets up access to it for the user by getting an
+access token, which will be used for all requests.
+
+ GIVEN a running Muck
+
+ GIVEN a user tomjon with superuser access
+
+Create a simple resource. Assign it to another user. Remember its id.
+
+ WHEN user tomjon makes request POST /res
+ ... with header "Muck-User: verence" and body { "foo": "bar" }
+ THEN status code is 201
+ THEN remember resource id as ID
+ THEN remember resource revision as REV1
+ THEN response has header "Muck-Owner: verence"
+
+Retrieve the resource.
+
+ WHEN user tomjon makes request GET /res with header "Muck-Id: ${ID}"
+ THEN status code is 200
+ THEN response body is { "foo": "bar" }
+ THEN response has header "Muck-Id: ${ID}"
+ THEN response has header "Muck-Revision: ${REV1}"
+ THEN response has header "Muck-Owner: verence"
+
+Make sure Verence CAN retrieve, update, or delete the resource.
+
+ WHEN user verence makes request GET /res with header "Muck-Id: ${ID}"
+ THEN status code is 200
+ THEN response body is { "foo": "bar" }
+ THEN response has header "Muck-Id: ${ID}"
+ THEN response has header "Muck-Revision: ${REV1}"
+ THEN response has header "Muck-Owner: verence"
+
+All done.
+
+ FINALLY Muck is stopped
diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn
index c81d1ef..22d6463 100644
--- a/yarns/900-implements.yarn
+++ b/yarns/900-implements.yarn
@@ -12,6 +12,14 @@
IMPLEMENTS FINALLY Muck is stopped
stop_muck()
+## Create users
+
+
+ IMPLEMENTS GIVEN a user (\S+) with superuser access
+ user = get_next_match()
+ users = V['superusers'] or []
+ V['superusers'] = users + [user]
+
## HTTP requests
IMPLEMENTS WHEN user (\S+) makes request POST /res with body (.*)
@@ -19,6 +27,13 @@
body = get_expanded_match()
POST(user, '/res', {}, json.loads(body))
+ IMPLEMENTS WHEN user (\S+) makes request POST /res with header "(\S+): (.+)" and body (.*)
+ user = get_expanded_match()
+ header = get_expanded_match()
+ value = get_expanded_match()
+ body = get_expanded_match()
+ POST(user, '/res', {header:value}, json.loads(body))
+
IMPLEMENTS WHEN user (\S+) makes request GET /res with header "(\S+): (.+)"
user = get_expanded_match()
header = get_expanded_match()
diff --git a/yarns/lib.py b/yarns/lib.py
index 583dff5..f64af8d 100644
--- a/yarns/lib.py
+++ b/yarns/lib.py
@@ -57,6 +57,7 @@ def start_muck():
pathname, config_filename,
]
subprocess.check_call(argv)
+ time.sleep(2)
V['base_url'] = 'http://127.0.0.1:{}'.format(12765)
@@ -72,6 +73,8 @@ def create_test_token(sub):
iss = 'test-issuer'
aud = 'test-audience'
scopes = ['create', 'update', 'show', 'delete']
+ if sub in (V['superusers'] or []):
+ scopes.append('super')
lifetime = 3600
return create_token(key_text, iss, aud, sub, scopes, lifetime)