summaryrefslogtreecommitdiff
path: root/users/test/integration/api/python/signup_and_login.py
blob: 2d796885a086a1d967d6cd06f1a590229f87472f (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
45
46
47
48
#!/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
  print " () " + json.dumps(requests.utils.dict_from_cookiejar(response.cookies))
  return json.loads(response.text)

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

def authenticate(session, login):
  params = {
      'login': login,
      'A': '12345',
      }
  init = session.post(server + '/sessions', data = params)
  cookies = requests.utils.dict_from_cookiejar(init.cookies)
  init = session.post(server + '/sessions', data = params, cookies = cookies)
  print "(%) " + json.dumps(cookies)
  return session.put(server + '/sessions/' + login, data = {'client_auth': '123'}, cookies = cookies)

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']))