summaryrefslogtreecommitdiff
path: root/test/integration/api/python/signup_and_login.py
blob: ac611d791dcd70d8d999a8d619de45ef34a76496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python

# FAILS
#
# This test is currently failing for me because the session is not kept.
# Played with it a bunch - is probably messed up right now as well.


server = 'http://localhost:3000'

import requests
import json
import string
import random

def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
  return ''.join(random.choice(chars) for x in range(size))

def print_and_parse(response):
  print response.request.method + ': ' + response.url
  print "    " + json.dumps(response.request.data)
  print " -> " + response.text
  return json.loads(response.text)

def signup(session):
  user_params = {
      'user[login]': id_generator(),
      'user[password_verifier]': '12345',
      'user[password_salt]': 'AB54321'
      }
  return session.post(server + '/users.json', data = user_params)

def authenticate(session, login):
  params = {
      'login': login,
      'A': '12345',
      }
  init = print_and_parse(session.post(server + '/sessions', data = params))
  return session.put(server + '/sessions/' + login, data = {'client_auth': '123'})

session = requests.session()
user = print_and_parse(signup(session))
# SRP signup would happen here and calculate M hex
auth = print_and_parse(authenticate(session, user['login']))