summaryrefslogtreecommitdiff
path: root/yarns
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-11-16 15:25:56 +0100
committerLars Wirzenius <liw@liw.fi>2017-11-16 15:25:56 +0100
commit8a72debe0a357726947b0a281e8c59ec5cd60a35 (patch)
treeaac62a932e446385090a4bcc6c9dfde6bae8cb01 /yarns
parentb704146516631f5e561b50ae3a1154f306ffb955 (diff)
downloadqvisqve-8a72debe0a357726947b0a281e8c59ec5cd60a35.tar.gz
Add: check can start/stop salami or run against remote
Diffstat (limited to 'yarns')
-rw-r--r--yarns/900-implements.yarn53
-rw-r--r--yarns/900-local.yarn93
-rw-r--r--yarns/900-remote.yarn47
3 files changed, 140 insertions, 53 deletions
diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn
index a8678e9..c04b6a5 100644
--- a/yarns/900-implements.yarn
+++ b/yarns/900-implements.yarn
@@ -2,59 +2,6 @@
This chapter shows the scenario step implementations.
-## Start and stop Salami
-
-Start a Salami running in the background.
-
- IMPLEMENTS GIVEN a running salami instance
- import os, time, cliapp, yaml, yarnutils
- privkey, pubkey = create_token_signing_key_pair()
- open('key', 'w').write(privkey)
- vars['aud'] = 'http://api.test.example.com'
- vars['iss'] = 'salami.yarn'
- vars['privkey'] = privkey
- vars['pubkey'] = pubkey
- vars['api.log'] = 'salami.log'
- vars['gunicorn3.log'] = 'gunicorn3.log'
- vars['pid-file'] = 'pid'
- vars['port'] = cliapp.runcmd([os.path.join(srcdir, 'randport' )]).strip()
- vars['API_URL'] = 'http://127.0.0.1:{}'.format(vars['port'])
- config = {
- 'log': [
- {
- 'filename': vars['api.log'],
- },
- ],
- 'token-public-key': vars['pubkey'],
- 'token-issuer': vars['iss'],
- 'token-audience': vars['aud'],
- }
- config = add_postgres_config(config)
- env = dict(os.environ)
- env['SALAMI_CONFIG'] = os.path.join(datadir, 'salami.yaml')
- yaml.safe_dump(config, open(env['SALAMI_CONFIG'], 'w'))
- argv = [
- 'gunicorn3',
- '--daemon',
- '--bind', '127.0.0.1:{}'.format(vars['port']),
- '-p', vars['pid-file'],
- 'salami.backend:app',
- ]
- cliapp.runcmd(argv, env=env, stdout=None, stderr=None)
- until = time.time() + 2.0
- while time.time() < until and not os.path.exists(vars['pid-file']):
- time.sleep(0.01)
- assert os.path.exists(vars['pid-file'])
-
-## Stop a Salami we started
-
- IMPLEMENTS FINALLY salami is stopped
- import os, signal, yarnutils
- filename = vars['pid-file']
- if os.path.exists(filename):
- pid = int(cat(filename))
- os.kill(pid, signal.SIGTERM)
-
## API requests of various kinds
IMPLEMENTS WHEN client requests GET (/.+) without token
diff --git a/yarns/900-local.yarn b/yarns/900-local.yarn
new file mode 100644
index 0000000..788c743
--- /dev/null
+++ b/yarns/900-local.yarn
@@ -0,0 +1,93 @@
+<!--
+
+Copyright 2017 Lars Wirzenius
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+-->
+
+# Scenario step implementations for locally managed Salami
+
+## Authentication setup
+
+ IMPLEMENTS GIVEN an RSA key pair for token signing
+ argv = [
+ os.path.join(srcdir, 'generate-rsa-key'),
+ 'token.key',
+ ]
+ cliapp.runcmd(argv, stdout=None, stderr=None)
+
+ IMPLEMENTS GIVEN an access token for (\S+) with scopes (.+)
+ user = get_next_match()
+ scopes = get_next_match()
+ key = open('token.key').read()
+ argv = [
+ os.path.join(srcdir, 'create-token'),
+ scopes,
+ ]
+ token = cliapp.runcmd(argv, feed_stdin=key)
+ store_token(user, token)
+ vars['issuer'] = 'localhost'
+ vars['audience'] = 'localhost'
+
+## Start Salami
+
+ IMPLEMENTS GIVEN a running salami instance
+ import os, time, cliapp, yaml, yarnutils
+ privkey, pubkey = create_token_signing_key_pair()
+ open('key', 'w').write(privkey)
+ vars['aud'] = 'http://api.test.example.com'
+ vars['iss'] = 'salami.yarn'
+ vars['privkey'] = privkey
+ vars['pubkey'] = pubkey
+ vars['api.log'] = 'salami.log'
+ vars['gunicorn3.log'] = 'gunicorn3.log'
+ vars['pid-file'] = 'pid'
+ vars['port'] = cliapp.runcmd([os.path.join(srcdir, 'randport' )]).strip()
+ vars['API_URL'] = 'http://127.0.0.1:{}'.format(vars['port'])
+ config = {
+ 'log': [
+ {
+ 'filename': vars['api.log'],
+ },
+ ],
+ 'token-public-key': vars['pubkey'],
+ 'token-issuer': vars['iss'],
+ 'token-audience': vars['aud'],
+ }
+ config = add_postgres_config(config)
+ env = dict(os.environ)
+ env['SALAMI_CONFIG'] = os.path.join(datadir, 'salami.yaml')
+ yaml.safe_dump(config, open(env['SALAMI_CONFIG'], 'w'))
+ argv = [
+ 'gunicorn3',
+ '--daemon',
+ '--bind', '127.0.0.1:{}'.format(vars['port']),
+ '-p', vars['pid-file'],
+ 'salami.backend:app',
+ ]
+ cliapp.runcmd(argv, env=env, stdout=None, stderr=None)
+ until = time.time() + 2.0
+ while time.time() < until and not os.path.exists(vars['pid-file']):
+ time.sleep(0.01)
+ assert os.path.exists(vars['pid-file'])
+
+## Stop a Salami we started
+
+ IMPLEMENTS FINALLY salami is stopped
+ import os, signal, yarnutils
+ filename = vars['pid-file']
+ if os.path.exists(filename):
+ pid = int(cat(filename))
+ os.kill(pid, signal.SIGTERM)
diff --git a/yarns/900-remote.yarn b/yarns/900-remote.yarn
new file mode 100644
index 0000000..29dc8bf
--- /dev/null
+++ b/yarns/900-remote.yarn
@@ -0,0 +1,47 @@
+<!--
+
+Copyright 2017 Lars Wirzenius
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+-->
+
+# Scenario step implementations for remote Salami
+
+## Authentication setup
+
+ IMPLEMENTS GIVEN an RSA key pair for token signing
+ vars['private_key_file'] = os.environ['ICK_PRIVATE_KEY']
+ assertTrue(os.path.exists(vars['private_key_file']))
+
+ IMPLEMENTS GIVEN an access token for (\S+) with scopes (.+)
+ user = get_next_match()
+ scopes = get_next_match()
+ key = open(vars['private_key_file']).read()
+ argv = [
+ os.path.join(srcdir, 'create-token'),
+ scopes,
+ ]
+ token = cliapp.runcmd(argv, feed_stdin=key)
+ store_token(user, token)
+ vars['issuer'] = 'localhost'
+ vars['audience'] = 'localhost'
+
+## Start and stop Salami
+
+ IMPLEMENTS GIVEN a running salami instance
+ vars['url'] = os.environ['ICK_URL']
+
+ IMPLEMENTS FINALLY salami is stopped
+ pass