summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-01-31 20:28:19 +0200
committerLars Wirzenius <liw@liw.fi>2017-01-31 20:28:19 +0200
commit3fe2aadd2a1c58435fdda78b2c789781ab1fb769 (patch)
treece6368e0576b2ddbd514221c78c4260705a50be8
parent7b29338ff9646755e91442ff96f9968741daf1b6 (diff)
downloadserver-yarns-3fe2aadd2a1c58435fdda78b2c789781ab1fb769.tar.gz
Fix things so tests pass
-rw-r--r--000.yarn2
-rw-r--r--100-mail.yarn2
-rw-r--r--900-implements.yarn41
-rwxr-xr-xcheck4
-rw-r--r--yarnhelper.py8
5 files changed, 33 insertions, 24 deletions
diff --git a/000.yarn b/000.yarn
index de56fa2..2f98da0 100644
--- a/000.yarn
+++ b/000.yarn
@@ -24,4 +24,4 @@ that need to be updated.
Do this with:
EXAMPLE
- yarn --env SERVER=new.example.com ...
+ yarn --env ADDRESS=new.example.com ...
diff --git a/100-mail.yarn b/100-mail.yarn
index 48a2f1a..0e1b6cc 100644
--- a/100-mail.yarn
+++ b/100-mail.yarn
@@ -48,4 +48,4 @@ utility. Each password should be stored using a name
WHEN someone sends mail to bugs@liw.fi with subject $R
THEN mailbox of distix has a mail with subject $R
- AND mailbox of distix has a mail with subject $R
+ AND mailbox of liw has a mail with subject $R
diff --git a/900-implements.yarn b/900-implements.yarn
index 9a2493f..da6d961 100644
--- a/900-implements.yarn
+++ b/900-implements.yarn
@@ -5,16 +5,16 @@
IMPLEMENTS GIVEN server is also known as (\S+)
import yarnhelper
h = yarnhelper.YarnHelper()
- h.set_variable('SERVER', h.get_next_match())
+ h.set_variable('ALIAS', h.get_next_match())
## HTTP requests
IMPLEMENTS WHEN user fetches (\S+)
- import yarnhelper
+ import os, yarnhelper
h = yarnhelper.YarnHelper()
- server = h.get_variable('SERVER')
+ address = os.environ['ADDRESS']
url = h.get_next_match()
- status, body = h.http_get(server, url)
+ status, body = h.http_get(address, url)
h.set_variable('http_status', status)
h.set_variable('http_body', body)
@@ -38,9 +38,9 @@
IMPLEMENTS WHEN user runs Gitano (.*)
import os, re, cliapp, yarnhelper
h = yarnhelper.YarnHelper()
- server = os.environ['SERVER']
+ address = os.environ['ADDRESS']
cmd = h.get_next_match()
- argv = ['ssh', 'git@' + server] + cmd.split()
+ argv = ['ssh', 'git@' + address] + cmd.split()
exit, out, err = cliapp.runcmd_unchecked(argv)
h.set_variable('argv', argv)
h.set_variable('exit', int(exit))
@@ -50,9 +50,9 @@
IMPLEMENTS WHEN user clones the (\S+) repository over git://
import os, re, cliapp, yarnhelper
h = yarnhelper.YarnHelper()
- server = os.environ['SERVER']
+ address = os.environ['ADDRESS']
repo = h.get_next_match()
- url = 'git://{}/{}'.format(server, repo)
+ url = 'git://{}/{}'.format(address, repo)
argv = ['git', 'clone', url]
exit, out, err = cliapp.runcmd_unchecked(argv, cwd=os.environ['DATADIR'])
h.set_variable('argv', argv)
@@ -105,15 +105,16 @@
## Send mail over SMTP+TLS
IMPLEMENTS WHEN someone sends mail to (\S+) with subject \$(\S+)
- import smtplib, sys, yarnhelper
+ import os, smtplib, sys, yarnhelper
h = yarnhelper.YarnHelper()
to_addr = h.get_next_match()
subject_key = h.get_next_match()
- server_name = h.get_variable('SERVER')
+ subject = h.get_variable(subject_key)
+ address = os.environ['ADDRESS']
from_addr = 'someone@example.com'
msg = 'From: {}\nTo: {}\nSubject: {}\n\nThis is the body\n'.format(
from_addr, to_addr, subject)
- server = smtplib.SMTP(server_name)
+ server = smtplib.SMTP(address)
server.set_debuglevel(True)
server.starttls()
server.sendmail(from_addr, to_addr, msg)
@@ -122,16 +123,21 @@
## Check for a mail in a mailbox
IMPLEMENTS THEN mailbox of (\S+) has a mail with subject \$(\S+)
- import email, imaplib, subprocess, yarnhelper
+ import email, imaplib, os, subprocess, yarnhelper
h = yarnhelper.YarnHelper()
user = h.get_next_match()
- subject = h.get_next_match()
- server = h.get_variable('SERVER')
- pass_name = 'server-yarns/imap/{}@{}'.format(user, server)
- p = subprocess.Popen(['pass', 'show', pass_name], stdout=subprocess.PIPE)
+ subject_key = h.get_next_match()
+ subject = h.get_variable(subject_key)
+ print 'Wanted:', subject
+ address = os.environ['ADDRESS']
+ pass_name = 'server-yarns/imap/{}@{}'.format(user, address)
+ pass_home = os.environ['PASS_HOME']
+ p = subprocess.Popen(
+ ['env', 'HOME={}'.format(pass_home), 'pass', 'show', pass_name],
+ stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
password = stdout.rstrip()
- m = imaplib.IMAP4_SSL(server)
+ m = imaplib.IMAP4_SSL(address)
m.login(user, password)
m.select('INBOX', True)
typ, data = m.search(None, 'ALL')
@@ -140,6 +146,7 @@
typ, data = m.fetch(num, '(RFC822)')
typ, text = data[0]
msg = email.message_from_string(text)
+ print 'Subject:', msg['Subject']
got_it = got_it or (msg['Subject'] == subject)
m.close()
m.logout()
diff --git a/check b/check
index 847edd2..62ba0ac 100755
--- a/check
+++ b/check
@@ -9,8 +9,10 @@ variables="$(mktemp)"
trap 'rm $variables' EXIT
python -m CoverageTestRunner
-yarn --env "SERVER=$address" \
+yarn --env "ADDRESS=$address" \
--env 'PYTHONPATH=.' \
+ --env "PASSWORD_STORE_DIR=$PASSWORD_STORE_DIR" \
+ --env "PASS_HOME=$HOME" \
--env "VARIABLES=$variables" \
--env "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" \
--env "SSH_AGENT_PID=$SSH_AGENT_PID" \
diff --git a/yarnhelper.py b/yarnhelper.py
index 51b4d4b..ee2a901 100644
--- a/yarnhelper.py
+++ b/yarnhelper.py
@@ -67,21 +67,21 @@ class YarnHelper(object):
yaml.safe_dump(variables, f)
def construct_aliased_http_request(
- self, server, method, url, data=None, headers=None):
+ self, address, method, url, data=None, headers=None):
if headers is None:
headers = {}
parts = list(urlparse.urlparse(url))
headers['Host'] = parts[1]
- parts[1] = server
+ parts[1] = address
aliased_url = urlparse.urlunparse(parts)
r = requests.Request(method, aliased_url, data=data, headers=headers)
return r.prepare()
- def http_get(self, server, url): # pragma: no cover
- r = self.construct_aliased_http_request(server, 'GET', url)
+ def http_get(self, address, url): # pragma: no cover
+ r = self.construct_aliased_http_request(address, 'GET', url)
s = requests.Session()
resp = s.send(r)
return resp.status_code, resp.content