Mercurial > p > roundup > code
annotate test/rest_common.py @ 7587:8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
Replace calls with equivalent that produces timezone aware dates
rather than naive dates.
Also some flake8 fixes for test/rest_common.py.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 25 Jul 2023 16:30:10 -0400 |
| parents | 978285986b2c |
| children | be6cb2e0d471 |
| rev | line source |
|---|---|
|
6090
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
1 import pytest |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
2 import unittest |
|
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
3 import shutil |
|
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
4 import errno |
| 5583 | 5 |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
6 from time import sleep |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
7 from datetime import datetime, timedelta |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
8 from roundup.anypy.cgi_ import cgi |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
9 from roundup.anypy.datetime_ import utcnow |
| 6361 | 10 from roundup.test.tx_Source_detector import init as tx_Source_init |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
11 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
12 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
13 try: |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
14 from datetime import timezone |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
15 myutc = timezone.utc |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
16 except ImportError: |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
17 # python 2 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
18 from datetime import tzinfo |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
19 ZERO = timedelta(0) |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
20 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
21 class UTC(tzinfo): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
22 """UTC""" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
23 def utcoffset(self, dt): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
24 return ZERO |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
25 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
26 def tzname(self, dt): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
27 return "UTC" |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
28 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
29 def dst(self, dt): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
30 return ZERO |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
31 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
32 myutc = UTC() |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
33 |
| 5583 | 34 from roundup.cgi.exceptions import * |
|
5706
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
35 from roundup.hyperdb import HyperdbValueError |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
36 from roundup.exceptions import * |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
37 from roundup import password, hyperdb |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
38 from roundup.rest import RestfulInstance, calculate_etag |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
39 from roundup.cgi import client |
|
6185
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
40 from roundup.anypy.strings import b2s, s2b, us2u |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
41 import random |
| 5583 | 42 |
|
5733
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
43 from roundup.backends.sessions_dbm import OneTimeKeys |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
44 from roundup.anypy.dbm_ import whichdb |
|
5733
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
45 |
| 5602 | 46 from .db_test_base import setupTracker |
| 5583 | 47 |
|
6366
f2c31f5ec50b
Move mocknull from test to roundup/test
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6361
diff
changeset
|
48 from roundup.test.mocknull import MockNull |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
49 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
50 from io import BytesIO |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
51 import json |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
52 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
53 from copy import copy |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
54 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
55 try: |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
56 import jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
57 skip_jwt = lambda func, *args, **kwargs: func |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
58 except ImportError: |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
59 from .pytest_patcher import mark_class |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
60 jwt = None |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
61 skip_jwt = mark_class(pytest.mark.skip( |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
62 reason='Skipping JWT tests: jwt library not available')) |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
63 |
| 5583 | 64 NEEDS_INSTANCE = 1 |
| 65 | |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
66 |
|
5601
fcbeff272828
Integrate REST tests into db framework
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5600
diff
changeset
|
67 class TestCase(): |
| 5583 | 68 |
| 69 backend = None | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
70 url_pfx = 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/' |
| 5583 | 71 |
| 72 def setUp(self): | |
|
6314
a2fbd3592322
pyjwt 2.00 changed return type of jwt.encode from byte to str
John Rouillard <rouilj@ieee.org>
parents:
6312
diff
changeset
|
73 from packaging import version |
|
a2fbd3592322
pyjwt 2.00 changed return type of jwt.encode from byte to str
John Rouillard <rouilj@ieee.org>
parents:
6312
diff
changeset
|
74 |
| 5583 | 75 self.dirname = '_test_rest' |
| 76 # set up and open a tracker | |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
77 # Set optimize=True as code under test (Client.main()::determine_user) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
78 # will close and re-open the database on user changes. This wipes |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
79 # out additions to the schema needed for testing. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
80 self.instance = setupTracker(self.dirname, self.backend, optimize=True) |
| 5583 | 81 |
| 82 # open the database | |
| 83 self.db = self.instance.open('admin') | |
| 84 | |
|
5733
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
85 # Create the Otk db. |
|
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
86 # This allows a test later on to open the existing db and |
|
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
87 # set a class attribute to test the open retry loop |
|
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
88 # just as though this process was using a pre-existing db |
|
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
89 # rather then the new one we create. |
|
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
90 otk = OneTimeKeys(self.db) |
|
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
91 otk.set('key', key="value") |
|
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
92 |
| 5583 | 93 # Get user id (user4 maybe). Used later to get data from db. |
| 94 self.joeid = self.db.user.create( | |
| 95 username='joe', | |
| 96 password=password.Password('random'), | |
| 97 address='random@home.org', | |
| 98 realname='Joe Random', | |
| 99 roles='User' | |
| 100 ) | |
| 101 | |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
102 self.db.user.set('1', address="admin@admin.com") |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
103 self.db.user.set('2', address="anon@admin.com") |
| 5583 | 104 self.db.commit() |
| 105 self.db.close() | |
| 106 self.db = self.instance.open('joe') | |
| 5604 | 107 # Allow joe to retire |
| 108 p = self.db.security.addPermission(name='Retire', klass='issue') | |
| 109 self.db.security.addPermissionToRole('User', p) | |
| 5583 | 110 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
111 # add set of roles for testing jwt's. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
112 self.db.security.addRole(name="User:email", |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
113 description="allow email by jwt") |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
114 # allow the jwt to access everybody's email addresses. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
115 # this makes it easier to differentiate between User and |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
116 # User:email roles by accessing the /rest/data/user |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
117 # endpoint |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
118 jwt_perms = self.db.security.addPermission( |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
119 name='View', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
120 klass='user', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
121 properties=('id', 'realname', 'address', 'username'), |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
122 description="Allow jwt access to email", |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
123 props_only=False) |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
124 self.db.security.addPermissionToRole("User:email", jwt_perms) |
|
5879
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
125 self.db.security.addPermissionToRole("User:email", "Rest Access") |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
126 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
127 # add set of roles for testing jwt's. |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
128 # this is like the user:email role, but it missing access to the rest endpoint. |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
129 self.db.security.addRole(name="User:emailnorest", |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
130 description="allow email by jwt") |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
131 jwt_perms = self.db.security.addPermission( |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
132 name='View', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
133 klass='user', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
134 properties=('id', 'realname', 'address', 'username'), |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
135 description="Allow jwt access to email but forget to allow rest", |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
136 props_only=False) |
|
5879
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
137 self.db.security.addPermissionToRole("User:emailnorest", jwt_perms) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
138 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
139 if jwt: |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
140 # must be 32 chars in length minimum (I think this is at least |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
141 # 256 bits of data) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
142 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
143 secret = "TestingTheJwtSecretTestingTheJwtSecret" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
144 self.db.config['WEB_JWT_SECRET'] = secret |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
145 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
146 # generate all timestamps in UTC. |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
147 base_datetime = datetime(1970, 1, 1, tzinfo=myutc) |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
148 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
149 # A UTC timestamp for now. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
150 dt = datetime.now(myutc) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
151 now_ts = int((dt - base_datetime).total_seconds()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
152 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
153 # one good for a minute |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
154 dt = dt + timedelta(seconds=60) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
155 plus1min_ts = int((dt - base_datetime).total_seconds()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
156 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
157 # one that expired a minute ago |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
158 dt = dt - timedelta(seconds=120) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
159 expired_ts = int((dt - base_datetime).total_seconds()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
160 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
161 # claims match what cgi/client.py::determine_user |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
162 # is looking for |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
163 claim = {'sub': self.db.getuid(), |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
164 'iss': self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
165 'aud': self.db.config.TRACKER_WEB, |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
166 'roles': ['User'], |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
167 'iat': now_ts, |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
168 'exp': plus1min_ts} |
|
6314
a2fbd3592322
pyjwt 2.00 changed return type of jwt.encode from byte to str
John Rouillard <rouilj@ieee.org>
parents:
6312
diff
changeset
|
169 |
|
a2fbd3592322
pyjwt 2.00 changed return type of jwt.encode from byte to str
John Rouillard <rouilj@ieee.org>
parents:
6312
diff
changeset
|
170 # in version 2.0.0 and newer jwt.encode returns string |
|
a2fbd3592322
pyjwt 2.00 changed return type of jwt.encode from byte to str
John Rouillard <rouilj@ieee.org>
parents:
6312
diff
changeset
|
171 # not bytestring. So we have to skip b2s conversion |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
172 |
|
6314
a2fbd3592322
pyjwt 2.00 changed return type of jwt.encode from byte to str
John Rouillard <rouilj@ieee.org>
parents:
6312
diff
changeset
|
173 if version.parse(jwt.__version__) >= version.parse('2.0.0'): |
|
a2fbd3592322
pyjwt 2.00 changed return type of jwt.encode from byte to str
John Rouillard <rouilj@ieee.org>
parents:
6312
diff
changeset
|
174 tostr = lambda x: x |
|
a2fbd3592322
pyjwt 2.00 changed return type of jwt.encode from byte to str
John Rouillard <rouilj@ieee.org>
parents:
6312
diff
changeset
|
175 else: |
|
a2fbd3592322
pyjwt 2.00 changed return type of jwt.encode from byte to str
John Rouillard <rouilj@ieee.org>
parents:
6312
diff
changeset
|
176 tostr = b2s |
|
a2fbd3592322
pyjwt 2.00 changed return type of jwt.encode from byte to str
John Rouillard <rouilj@ieee.org>
parents:
6312
diff
changeset
|
177 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
178 self.jwt = {} |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
179 self.claim = {} |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
180 # generate invalid claim with expired timestamp |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
181 self.claim['expired'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
182 self.claim['expired']['exp'] = expired_ts |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
183 self.jwt['expired'] = tostr(jwt.encode( |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
184 self.claim['expired'], secret, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
185 algorithm='HS256')) |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
186 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
187 # generate valid claim with user role |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
188 self.claim['user'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
189 self.claim['user']['exp'] = plus1min_ts |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
190 self.jwt['user'] = tostr(jwt.encode( |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
191 self.claim['user'], secret, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
192 algorithm='HS256')) |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
193 # generate invalid claim bad issuer |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
194 self.claim['badiss'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
195 self.claim['badiss']['iss'] = "http://someissuer/bugs" |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
196 self.jwt['badiss'] = tostr(jwt.encode( |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
197 self.claim['badiss'], secret, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
198 algorithm='HS256')) |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
199 # generate invalid claim bad aud(ience) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
200 self.claim['badaud'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
201 self.claim['badaud']['aud'] = "http://someaudience/bugs" |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
202 self.jwt['badaud'] = tostr(jwt.encode( |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
203 self.claim['badaud'], secret, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
204 algorithm='HS256')) |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
205 # generate invalid claim bad sub(ject) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
206 self.claim['badsub'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
207 self.claim['badsub']['sub'] = str("99") |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
208 self.jwt['badsub'] = tostr( |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
209 jwt.encode(self.claim['badsub'], secret, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
210 algorithm='HS256')) |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
211 # generate invalid claim bad roles |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
212 self.claim['badroles'] = copy(claim) |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
213 self.claim['badroles']['roles'] = ["badrole1", "badrole2"] |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
214 self.jwt['badroles'] = tostr(jwt.encode( |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
215 self.claim['badroles'], secret, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
216 algorithm='HS256')) |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
217 # generate valid claim with limited user:email role |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
218 self.claim['user:email'] = copy(claim) |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
219 self.claim['user:email']['roles'] = ["user:email"] |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
220 self.jwt['user:email'] = tostr(jwt.encode( |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
221 self.claim['user:email'], secret, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
222 algorithm='HS256')) |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
223 |
|
5879
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
224 # generate valid claim with limited user:emailnorest role |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
225 self.claim['user:emailnorest'] = copy(claim) |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
226 self.claim['user:emailnorest']['roles'] = ["user:emailnorest"] |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
227 self.jwt['user:emailnorest'] = tostr(jwt.encode( |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
228 self.claim['user:emailnorest'], secret, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
229 algorithm='HS256')) |
|
5879
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
230 |
| 5583 | 231 self.db.tx_Source = 'web' |
| 232 | |
| 233 self.db.issue.addprop(tx_Source=hyperdb.String()) | |
|
5690
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
234 self.db.issue.addprop(anint=hyperdb.Integer()) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
235 self.db.issue.addprop(afloat=hyperdb.Number()) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
236 self.db.issue.addprop(abool=hyperdb.Boolean()) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
237 self.db.issue.addprop(requireme=hyperdb.String(required=True)) |
|
6256
29c6dc8ed004
Test handling of unset transitive link field.
John Rouillard <rouilj@ieee.org>
parents:
6185
diff
changeset
|
238 self.db.user.addprop(issue=hyperdb.Link('issue')) |
| 5583 | 239 self.db.msg.addprop(tx_Source=hyperdb.String()) |
| 240 | |
| 241 self.db.post_init() | |
| 242 | |
| 6361 | 243 tx_Source_init(self.db) |
| 5583 | 244 |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
245 self.client_env = { |
| 5583 | 246 'PATH_INFO': 'http://localhost/rounduptest/rest/', |
| 247 'HTTP_HOST': 'localhost', | |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
248 'TRACKER_NAME': 'rounduptest', |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
249 'HTTP_ORIGIN': 'http://tracker.example' |
| 5583 | 250 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
251 self.dummy_client = client.Client(self.instance, MockNull(), |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
252 self.client_env, [], None) |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
253 self.dummy_client.request.headers.get = self.get_header |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
254 self.dummy_client.db = self.db |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
255 |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
256 self.empty_form = cgi.FieldStorage() |
|
7183
2de72f75f2f8
Production PBKDF rounds back to 2M, test 1k; fix empty_form (python2)
John Rouillard <rouilj@ieee.org>
parents:
7156
diff
changeset
|
257 # under python2 invoking: |
|
2de72f75f2f8
Production PBKDF rounds back to 2M, test 1k; fix empty_form (python2)
John Rouillard <rouilj@ieee.org>
parents:
7156
diff
changeset
|
258 # python2 -m pytest --durations=20 |
|
2de72f75f2f8
Production PBKDF rounds back to 2M, test 1k; fix empty_form (python2)
John Rouillard <rouilj@ieee.org>
parents:
7156
diff
changeset
|
259 # loads the form with: |
|
2de72f75f2f8
Production PBKDF rounds back to 2M, test 1k; fix empty_form (python2)
John Rouillard <rouilj@ieee.org>
parents:
7156
diff
changeset
|
260 # FieldStorage(None, None, [MiniFieldStorage('--durations', '2')]) |
|
2de72f75f2f8
Production PBKDF rounds back to 2M, test 1k; fix empty_form (python2)
John Rouillard <rouilj@ieee.org>
parents:
7156
diff
changeset
|
261 # Invoking it as: python2 -m pytest -v --durations=20 |
|
2de72f75f2f8
Production PBKDF rounds back to 2M, test 1k; fix empty_form (python2)
John Rouillard <rouilj@ieee.org>
parents:
7156
diff
changeset
|
262 # results in an empty list. In any case, force it to be empty. |
|
2de72f75f2f8
Production PBKDF rounds back to 2M, test 1k; fix empty_form (python2)
John Rouillard <rouilj@ieee.org>
parents:
7156
diff
changeset
|
263 self.empty_form.list = [] |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
264 self.terse_form = cgi.FieldStorage() |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
265 self.terse_form.list = [ |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
266 cgi.MiniFieldStorage('@verbose', '0'), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
267 ] |
| 5583 | 268 |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
269 self.server = RestfulInstance(self.dummy_client, self.db) |
| 5583 | 270 |
|
5710
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
271 self.db.Otk = self.db.getOTKManager() |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
272 |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
273 self.db.config['WEB_SECRET_KEY'] = "XyzzykrnKm45Sd" |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
274 |
| 5583 | 275 def tearDown(self): |
| 276 self.db.close() | |
| 277 try: | |
| 278 shutil.rmtree(self.dirname) | |
| 5602 | 279 except OSError as error: |
| 5583 | 280 if error.errno not in (errno.ENOENT, errno.ESRCH): |
| 281 raise | |
| 282 | |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
283 def get_header(self, header, not_found=None): |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
284 try: |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
285 return self.headers[header.lower()] |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
286 except (AttributeError, KeyError, TypeError): |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
287 if header.upper() in self.client_env: |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
288 return self.client_env[header.upper()] |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
289 return not_found |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
290 |
|
5865
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
291 def create_stati(self): |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
292 try: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
293 self.db.status.create(name='open', order='9') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
294 except ValueError: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
295 pass |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
296 try: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
297 self.db.status.create(name='closed', order='91') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
298 except ValueError: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
299 pass |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
300 try: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
301 self.db.priority.create(name='normal') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
302 except ValueError: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
303 pass |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
304 try: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
305 self.db.priority.create(name='critical') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
306 except ValueError: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
307 pass |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
308 |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
309 def create_sampledata(self): |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
310 """ Create sample data common to some test cases |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
311 """ |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
312 self.create_stati() |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
313 self.db.issue.create( |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
314 title='foo1', |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
315 status=self.db.status.lookup('open'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
316 priority=self.db.priority.lookup('normal'), |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
317 nosy=["1", "2"] |
|
5865
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
318 ) |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
319 issue_open_norm = self.db.issue.create( |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
320 title='foo2', |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
321 status=self.db.status.lookup('open'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
322 priority=self.db.priority.lookup('normal'), |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
323 assignedto="3" |
|
5865
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
324 ) |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
325 issue_open_crit = self.db.issue.create( |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
326 title='foo5', |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
327 status=self.db.status.lookup('open'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
328 priority=self.db.priority.lookup('critical') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
329 ) |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
330 |
| 5583 | 331 def testGet(self): |
| 332 """ | |
| 333 Retrieve all three users | |
| 334 obtain data for 'joe' | |
| 335 """ | |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
336 self.server.client.env.update({'REQUEST_METHOD': 'GET'}) |
| 5583 | 337 # Retrieve all three users. |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
338 results = self.server.get_collection('user', self.empty_form) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
339 self.assertEqual(self.dummy_client.response_code, 200) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
340 self.assertEqual(len(results['data']['collection']), 3) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
341 self.assertEqual(results['data']['@total_size'], 3) |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
342 print(self.dummy_client.additional_headers["X-Count-Total"]) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
343 self.assertEqual( |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
344 self.dummy_client.additional_headers["X-Count-Total"], |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
345 "3" |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
346 ) |
| 5583 | 347 |
| 348 # Obtain data for 'joe'. | |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
349 results = self.server.get_element('user', self.joeid, self.empty_form) |
|
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
350 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
351 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 352 self.assertEqual(results['attributes']['username'], 'joe') |
| 353 self.assertEqual(results['attributes']['realname'], 'Joe Random') | |
| 354 | |
| 5678 | 355 # Obtain data for 'joe' via username lookup. |
| 356 results = self.server.get_element('user', 'joe', self.empty_form) | |
| 357 results = results['data'] | |
| 358 self.assertEqual(self.dummy_client.response_code, 200) | |
| 359 self.assertEqual(results['attributes']['username'], 'joe') | |
| 360 self.assertEqual(results['attributes']['realname'], 'Joe Random') | |
| 361 | |
| 362 # Obtain data for 'joe' via username lookup (long form). | |
| 363 key = 'username=joe' | |
| 364 results = self.server.get_element('user', key, self.empty_form) | |
| 365 results = results['data'] | |
| 366 self.assertEqual(self.dummy_client.response_code, 200) | |
| 367 self.assertEqual(results['attributes']['username'], 'joe') | |
| 368 self.assertEqual(results['attributes']['realname'], 'Joe Random') | |
| 369 | |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
370 # Obtain data for 'joe'. |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
371 results = self.server.get_attribute( |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
372 'user', self.joeid, 'username', self.empty_form |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
373 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
374 self.assertEqual(self.dummy_client.response_code, 200) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
375 self.assertEqual(results['data']['data'], 'joe') |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
376 |
|
5872
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
377 def testGetTransitive(self): |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
378 """ |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
379 Retrieve all issues with an 'o' in status |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
380 sort by status.name (not order) |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
381 """ |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
382 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/' |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
383 # self.maxDiff=None |
|
5872
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
384 self.create_sampledata() |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
385 self.db.issue.set('2', status=self.db.status.lookup('closed')) |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
386 self.db.issue.set('3', status=self.db.status.lookup('chatting')) |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
387 expected = {'data': |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
388 {'@total_size': 2, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
389 'collection': [ |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
390 {'id': '2', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
391 'link': base_path + 'issue/2', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
392 'assignedto.issue': None, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
393 'status': |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
394 {'id': '10', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
395 'link': base_path + 'status/10' |
|
5872
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
396 } |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
397 }, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
398 {'id': '1', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
399 'link': base_path + 'issue/1', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
400 'assignedto.issue': None, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
401 'status': |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
402 {'id': '9', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
403 'link': base_path + 'status/9' |
|
5872
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
404 } |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
405 }, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
406 ]} |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
407 } |
|
5872
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
408 form = cgi.FieldStorage() |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
409 form.list = [ |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
410 cgi.MiniFieldStorage('status.name', 'o'), |
|
6256
29c6dc8ed004
Test handling of unset transitive link field.
John Rouillard <rouilj@ieee.org>
parents:
6185
diff
changeset
|
411 cgi.MiniFieldStorage('@fields', 'status,assignedto.issue'), |
|
5872
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
412 cgi.MiniFieldStorage('@sort', 'status.name'), |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
413 ] |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
414 results = self.server.get_collection('issue', form) |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
415 self.assertDictEqual(expected, results) |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
416 |
|
6554
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
417 def testGetBadTransitive(self): |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
418 """ |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
419 Mess up the names of various properties and make sure we get a 400 |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
420 and a somewhat useful error message. |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
421 """ |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
422 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/' |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
423 # self.maxDiff=None |
|
6554
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
424 self.create_sampledata() |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
425 self.db.issue.set('2', status=self.db.status.lookup('closed')) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
426 self.db.issue.set('3', status=self.db.status.lookup('chatting')) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
427 expected = [ |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
428 {'error': {'msg': KeyError('Unknown property: assignedto.isse',), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
429 'status': 400}}, |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
430 {'error': {'msg': KeyError('Unknown property: stat',), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
431 'status': 400}}, |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
432 {'error': {'msg': KeyError('Unknown property: status.nam',), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
433 'status': 400}}, |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
434 ] |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
435 |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
436 ## test invalid transitive property in @fields |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
437 form = cgi.FieldStorage() |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
438 form.list = [ |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
439 cgi.MiniFieldStorage('status.name', 'o'), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
440 cgi.MiniFieldStorage('@fields', 'status,assignedto.isse'), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
441 cgi.MiniFieldStorage('@sort', 'status.name'), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
442 ] |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
443 results = self.server.get_collection('issue', form) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
444 self.assertEqual(self.dummy_client.response_code, 400) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
445 self.assertEqual(repr(expected[0]['error']['msg']), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
446 repr(results['error']['msg'])) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
447 self.assertEqual(expected[0]['error']['status'], |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
448 results['error']['status']) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
449 |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
450 ## test invalid property in @fields |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
451 form = cgi.FieldStorage() |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
452 form.list = [ |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
453 cgi.MiniFieldStorage('status.name', 'o'), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
454 cgi.MiniFieldStorage('@fields', 'stat,assignedto.isuse'), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
455 cgi.MiniFieldStorage('@sort', 'status.name'), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
456 ] |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
457 results = self.server.get_collection('issue', form) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
458 self.assertEqual(self.dummy_client.response_code, 400) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
459 self.assertEqual(repr(expected[1]['error']['msg']), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
460 repr(results['error']['msg'])) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
461 self.assertEqual(expected[1]['error']['status'], |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
462 results['error']['status']) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
463 |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
464 ## test invalid transitive property in filter TODO |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
465 form = cgi.FieldStorage() |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
466 form.list = [ |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
467 cgi.MiniFieldStorage('status.nam', 'o'), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
468 cgi.MiniFieldStorage('@fields', 'status,assignedto.isuse'), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
469 cgi.MiniFieldStorage('@sort', 'status.name'), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
470 ] |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
471 results = self.server.get_collection('issue', form) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
472 # is currently 403 not 400 |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
473 self.assertEqual(self.dummy_client.response_code, 400) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
474 self.assertEqual(repr(expected[2]['error']['msg']), |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
475 repr(results['error']['msg'])) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
476 self.assertEqual(expected[2]['error']['status'], |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
477 results['error']['status']) |
|
576d630fc908
Fix error status for invalid props
John Rouillard <rouilj@ieee.org>
parents:
6539
diff
changeset
|
478 |
|
5874
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
479 def testGetExactMatch(self): |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
480 """ Retrieve all issues with an exact title |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
481 """ |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
482 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/' |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
483 # self.maxDiff=None |
|
5874
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
484 self.create_sampledata() |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
485 self.db.issue.set('2', title='This is an exact match') |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
486 self.db.issue.set('3', title='This is an exact match') |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
487 self.db.issue.set('1', title='This is AN exact match') |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
488 expected = {'data': |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
489 {'@total_size': 2, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
490 'collection': [ |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
491 {'id': '2', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
492 'link': base_path + 'issue/2', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
493 }, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
494 {'id': '3', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
495 'link': base_path + 'issue/3', |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
496 }, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
497 ]} |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
498 } |
|
5874
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
499 form = cgi.FieldStorage() |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
500 form.list = [ |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
501 cgi.MiniFieldStorage('title:', 'This is an exact match'), |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
502 cgi.MiniFieldStorage('@sort', 'status.name'), |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
503 ] |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
504 results = self.server.get_collection('issue', form) |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
505 self.assertDictEqual(expected, results) |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
506 |
|
5682
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
507 def testOutputFormat(self): |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
508 """ test of @fields and @verbose implementation """ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
509 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
510 self.maxDiff = 4000 |
|
5865
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
511 self.create_sampledata() |
|
5682
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
512 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/issue/' |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
513 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
514 # Check formating for issues status=open; @fields and verbose tests |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
515 form = cgi.FieldStorage() |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
516 form.list = [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
517 cgi.MiniFieldStorage('status', 'open'), |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
518 cgi.MiniFieldStorage('@fields', 'nosy,status,creator'), |
|
5682
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
519 cgi.MiniFieldStorage('@verbose', '2') |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
520 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
521 |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
522 expected = {'data': |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
523 {'@total_size': 3, |
|
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
524 'collection': [ { |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
525 'creator': {'id': '3', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
526 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
527 'username': 'joe'}, |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
528 'status': {'id': '9', |
|
5682
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
529 'name': 'open', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
530 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/status/9'}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
531 'id': '1', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
532 'nosy': [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
533 {'username': 'admin', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
534 'id': '1', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
535 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/1'}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
536 {'username': 'anonymous', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
537 'id': '2', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
538 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/2'} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
539 ], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
540 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
541 'title': 'foo1' }, |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
542 { 'creator': {'id': '3', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
543 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
544 'username': 'joe'}, |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
545 'status': { |
|
5682
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
546 'id': '9', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
547 'name': 'open', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
548 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/status/9' }, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
549 'id': '2', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
550 'nosy': [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
551 {'username': 'joe', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
552 'id': '3', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
553 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3'} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
554 ], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
555 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/2', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
556 'title': 'foo2'}, |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
557 {'creator': {'id': '3', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
558 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
559 'username': 'joe'}, |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
560 'status': { |
|
5682
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
561 'id': '9', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
562 'name': 'open', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
563 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/status/9'}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
564 'id': '3', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
565 'nosy': [], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
566 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/3', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
567 'title': 'foo5'} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
568 ]}} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
569 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
570 results = self.server.get_collection('issue', form) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
571 self.assertDictEqual(expected, results) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
572 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
573 # Check formating for issues status=open; @fields and verbose tests |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
574 form = cgi.FieldStorage() |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
575 form.list = [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
576 cgi.MiniFieldStorage('status', 'open') |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
577 # default cgi.MiniFieldStorage('@verbose', '1') |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
578 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
579 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
580 expected={'data': |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
581 {'@total_size': 3, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
582 'collection': [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
583 {'id': '1', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
584 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1',}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
585 { 'id': '2', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
586 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
587 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/2'}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
588 {'id': '3', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
589 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/3'} ]}} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
590 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
591 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
592 results = self.server.get_collection('issue', form) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
593 self.assertDictEqual(expected, results) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
594 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
595 # Generate failure case, unknown field. |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
596 form = cgi.FieldStorage() |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
597 form.list = [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
598 cgi.MiniFieldStorage('status', 'open'), |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
599 cgi.MiniFieldStorage('@fields', 'title,foo') |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
600 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
601 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
602 expected={'error': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
603 'msg': UsageError("Failed to find property 'foo' " |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
604 "for class issue.",), |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
605 'status': 400}} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
606 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
607 results = self.server.get_collection('issue', form) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
608 # I tried assertDictEqual but seems it can't handle |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
609 # the exception value of 'msg'. So I am using repr to check. |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
610 self.assertEqual(repr(sorted(expected['error'])), |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
611 repr(sorted(results['error'])) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
612 ) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
613 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
614 # Check formating for issues status=open; @fields and verbose tests |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
615 form = cgi.FieldStorage() |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
616 form.list = [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
617 cgi.MiniFieldStorage('status', 'open'), |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
618 cgi.MiniFieldStorage('@fields', 'nosy,status,assignedto'), |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
619 cgi.MiniFieldStorage('@verbose', '0') |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
620 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
621 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
622 expected={'data': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
623 '@total_size': 3, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
624 'collection': [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
625 {'assignedto': None, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
626 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
627 'status': '9', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
628 'nosy': ['1', '2'], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
629 'id': '1'}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
630 {'assignedto': '3', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
631 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/2', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
632 'status': '9', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
633 'nosy': ['3'], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
634 'id': '2'}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
635 {'assignedto': None, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
636 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/3', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
637 'status': '9', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
638 'nosy': [], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
639 'id': '3'}]}} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
640 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
641 results = self.server.get_collection('issue', form) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
642 print(results) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
643 self.assertDictEqual(expected, results) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
644 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
645 # check users |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
646 form = cgi.FieldStorage() |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
647 form.list = [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
648 cgi.MiniFieldStorage('@fields', 'username,queries,password'), |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
649 cgi.MiniFieldStorage('@verbose', '0') |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
650 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
651 # note this is done as user joe, so we only get queries |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
652 # and password for joe. |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
653 expected = {'data': {'collection': [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
654 {'id': '1', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
655 'username': 'admin', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
656 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/1'}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
657 {'id': '2', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
658 'username': 'anonymous', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
659 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/2'}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
660 {'password': '[password hidden scheme PBKDF2]', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
661 'id': '3', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
662 'queries': [], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
663 'username': 'joe', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
664 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3'}], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
665 '@total_size': 3}} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
666 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
667 results = self.server.get_collection('user', form) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
668 self.assertDictEqual(expected, results) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
669 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
670 ## Start testing get_element |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
671 form = cgi.FieldStorage() |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
672 form.list = [ |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
673 cgi.MiniFieldStorage('@fields', 'queries,password,creator'), |
|
5682
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
674 cgi.MiniFieldStorage('@verbose', '2') |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
675 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
676 expected = {'data': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
677 'id': '3', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
678 'type': 'user', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
679 '@etag': '', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
680 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
681 'attributes': { |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
682 'creator': {'id': '1', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
683 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/1', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
684 'username': 'admin'}, |
|
5682
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
685 'password': '[password hidden scheme PBKDF2]', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
686 'queries': [], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
687 'username': 'joe' |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
688 } |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
689 }} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
690 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
691 results = self.server.get_element('user', self.joeid, form) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
692 results['data']['@etag'] = '' # etag depends on date, set to empty |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
693 self.assertDictEqual(expected,results) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
694 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
695 form = cgi.FieldStorage() |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
696 form.list = [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
697 cgi.MiniFieldStorage('@fields', 'status:priority'), |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
698 cgi.MiniFieldStorage('@verbose', '1') |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
699 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
700 expected = {'data': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
701 'type': 'issue', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
702 'id': '3', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
703 'attributes': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
704 'status': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
705 'id': '9', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
706 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/status/9'}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
707 'priority': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
708 'id': '1', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
709 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/priority/1'}}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
710 '@etag': '', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
711 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/3'}} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
712 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
713 results = self.server.get_element('issue', "3", form) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
714 results['data']['@etag'] = '' # etag depends on date, set to empty |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
715 self.assertDictEqual(expected,results) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
716 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
717 form = cgi.FieldStorage() |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
718 form.list = [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
719 cgi.MiniFieldStorage('@fields', 'status,priority'), |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
720 cgi.MiniFieldStorage('@verbose', '0') |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
721 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
722 expected = {'data': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
723 'type': 'issue', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
724 'id': '3', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
725 'attributes': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
726 'status': '9', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
727 'priority': '1'}, |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
728 '@etag': '', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
729 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/3'}} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
730 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
731 results = self.server.get_element('issue', "3", form) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
732 results['data']['@etag'] = '' # etag depends on date, set to empty |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
733 self.assertDictEqual(expected,results) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
734 |
|
5865
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
735 def testSorting(self): |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
736 self.maxDiff = 4000 |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
737 self.create_sampledata() |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
738 self.db.issue.set('1', status='7') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
739 self.db.issue.set('2', status='2') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
740 self.db.issue.set('3', status='2') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
741 self.db.commit() |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
742 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/issue/' |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
743 # change some data for sorting on later |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
744 form = cgi.FieldStorage() |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
745 form.list = [ |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
746 cgi.MiniFieldStorage('@fields', 'status'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
747 cgi.MiniFieldStorage('@sort', 'status,-id'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
748 cgi.MiniFieldStorage('@verbose', '0') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
749 ] |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
750 |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
751 # status is sorted by orderprop (property 'order') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
752 # which provides the same ordering as the status ID |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
753 expected={'data': { |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
754 '@total_size': 3, |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
755 'collection': [ |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
756 {'link': base_path + '3', 'status': '2', 'id': '3'}, |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
757 {'link': base_path + '2', 'status': '2', 'id': '2'}, |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
758 {'link': base_path + '1', 'status': '7', 'id': '1'}]}} |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
759 |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
760 results = self.server.get_collection('issue', form) |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
761 self.assertDictEqual(expected, results) |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
762 |
|
6090
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
763 def testTransitiveField(self): |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
764 """ Test a transitive property in @fields """ |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
765 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/' |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
766 # create sample data |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
767 self.create_stati() |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
768 self.db.issue.create( |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
769 title='foo4', |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
770 status=self.db.status.lookup('closed'), |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
771 priority=self.db.priority.lookup('critical') |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
772 ) |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
773 # Retrieve all issue @fields=status.name |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
774 form = cgi.FieldStorage() |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
775 form.list = [ |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
776 cgi.MiniFieldStorage('@fields', 'status.name') |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
777 ] |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
778 results = self.server.get_collection('issue', form) |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
779 self.assertEqual(self.dummy_client.response_code, 200) |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
780 |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
781 exp = [ |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
782 {'link': base_path + 'issue/1', 'id': '1', 'status.name': 'closed'}] |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
783 self.assertEqual(results['data']['collection'], exp) |
|
e097ff5064b8
Allow transitive properties in @fields in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5993
diff
changeset
|
784 |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
785 def testFilter(self): |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
786 """ |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
787 Retrieve all three users |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
788 obtain data for 'joe' |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
789 """ |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
790 # create sample data |
|
5865
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
791 self.create_stati() |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
792 self.db.issue.create( |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
793 title='foo4', |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
794 status=self.db.status.lookup('closed'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
795 priority=self.db.priority.lookup('critical') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
796 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
797 self.db.issue.create( |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
798 title='foo1', |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
799 status=self.db.status.lookup('open'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
800 priority=self.db.priority.lookup('normal') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
801 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
802 issue_open_norm = self.db.issue.create( |
|
5842
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
803 title='foo2 normal', |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
804 status=self.db.status.lookup('open'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
805 priority=self.db.priority.lookup('normal') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
806 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
807 issue_closed_norm = self.db.issue.create( |
|
5842
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
808 title='foo3 closed normal', |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
809 status=self.db.status.lookup('closed'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
810 priority=self.db.priority.lookup('normal') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
811 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
812 issue_closed_crit = self.db.issue.create( |
|
5842
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
813 title='foo4 closed', |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
814 status=self.db.status.lookup('closed'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
815 priority=self.db.priority.lookup('critical') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
816 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
817 issue_open_crit = self.db.issue.create( |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
818 title='foo5', |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
819 status=self.db.status.lookup('open'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
820 priority=self.db.priority.lookup('critical') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
821 ) |
|
5623
1c4adab65faf
use config file setting for creating tracker uri
John Rouillard <rouilj@ieee.org>
parents:
5604
diff
changeset
|
822 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/issue/' |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
823 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
824 # Retrieve all issue status=open |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
825 form = cgi.FieldStorage() |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
826 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
827 cgi.MiniFieldStorage('status', 'open') |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
828 ] |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
829 results = self.server.get_collection('issue', form) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
830 self.assertEqual(self.dummy_client.response_code, 200) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
831 self.assertIn(get_obj(base_path, issue_open_norm), |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
832 results['data']['collection']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
833 self.assertIn(get_obj(base_path, issue_open_crit), |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
834 results['data']['collection']) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
835 self.assertNotIn( |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
836 get_obj(base_path, issue_closed_norm), |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
837 results['data']['collection'] |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
838 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
839 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
840 # Retrieve all issue status=closed and priority=critical |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
841 form = cgi.FieldStorage() |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
842 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
843 cgi.MiniFieldStorage('status', 'closed'), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
844 cgi.MiniFieldStorage('priority', 'critical') |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
845 ] |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
846 results = self.server.get_collection('issue', form) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
847 self.assertEqual(self.dummy_client.response_code, 200) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
848 self.assertIn(get_obj(base_path, issue_closed_crit), |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
849 results['data']['collection']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
850 self.assertNotIn(get_obj(base_path, issue_open_crit), |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
851 results['data']['collection']) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
852 self.assertNotIn( |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
853 get_obj(base_path, issue_closed_norm), |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
854 results['data']['collection'] |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
855 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
856 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
857 # Retrieve all issue status=closed and priority=normal,critical |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
858 form = cgi.FieldStorage() |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
859 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
860 cgi.MiniFieldStorage('status', 'closed'), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
861 cgi.MiniFieldStorage('priority', 'normal,critical') |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
862 ] |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
863 results = self.server.get_collection('issue', form) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
864 self.assertEqual(self.dummy_client.response_code, 200) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
865 self.assertIn(get_obj(base_path, issue_closed_crit), |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
866 results['data']['collection']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
867 self.assertIn(get_obj(base_path, issue_closed_norm), |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
868 results['data']['collection']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
869 self.assertNotIn(get_obj(base_path, issue_open_crit), |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
870 results['data']['collection']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
871 self.assertNotIn(get_obj(base_path, issue_open_norm), |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
872 results['data']['collection']) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
873 |
|
5842
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
874 # Retrieve all issue status=closed and priority=normal,critical |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
875 # using duplicate priority key's. |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
876 form = cgi.FieldStorage() |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
877 form.list = [ |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
878 cgi.MiniFieldStorage('status', 'closed'), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
879 cgi.MiniFieldStorage('priority', 'normal'), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
880 cgi.MiniFieldStorage('priority', 'critical') |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
881 ] |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
882 results = self.server.get_collection('issue', form) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
883 self.assertEqual(self.dummy_client.response_code, 200) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
884 self.assertIn(get_obj(base_path, issue_closed_crit), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
885 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
886 self.assertIn(get_obj(base_path, issue_closed_norm), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
887 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
888 self.assertNotIn(get_obj(base_path, issue_open_crit), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
889 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
890 self.assertNotIn(get_obj(base_path, issue_open_norm), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
891 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
892 |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
893 # Retrieve all issues with title containing |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
894 # closed, normal and 3 using duplicate title filterkeys |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
895 form = cgi.FieldStorage() |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
896 form.list = [ |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
897 cgi.MiniFieldStorage('title', 'closed'), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
898 cgi.MiniFieldStorage('title', 'normal'), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
899 cgi.MiniFieldStorage('title', '3') |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
900 ] |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
901 results = self.server.get_collection('issue', form) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
902 self.assertEqual(self.dummy_client.response_code, 200) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
903 self.assertNotIn(get_obj(base_path, issue_closed_crit), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
904 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
905 self.assertIn(get_obj(base_path, issue_closed_norm), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
906 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
907 self.assertNotIn(get_obj(base_path, issue_open_crit), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
908 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
909 self.assertNotIn(get_obj(base_path, issue_open_norm), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
910 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
911 self.assertEqual(len(results['data']['collection']), 1) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
912 |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
913 # Retrieve all issues (no hits) with title containing |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
914 # closed, normal and foo3 in this order using title filter |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
915 form = cgi.FieldStorage() |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
916 form.list = [ |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
917 cgi.MiniFieldStorage('title', 'closed normal foo3') |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
918 ] |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
919 results = self.server.get_collection('issue', form) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
920 self.assertEqual(self.dummy_client.response_code, 200) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
921 self.assertNotIn(get_obj(base_path, issue_closed_crit), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
922 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
923 self.assertNotIn(get_obj(base_path, issue_closed_norm), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
924 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
925 self.assertNotIn(get_obj(base_path, issue_open_crit), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
926 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
927 self.assertNotIn(get_obj(base_path, issue_open_norm), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
928 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
929 self.assertEqual(len(results['data']['collection']), 0) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
930 |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
931 # Retrieve all issues with title containing |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
932 # foo3, closed and normal in this order using title filter |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
933 form = cgi.FieldStorage() |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
934 form.list = [ |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
935 cgi.MiniFieldStorage('title', 'foo3 closed normal') |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
936 ] |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
937 results = self.server.get_collection('issue', form) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
938 self.assertEqual(self.dummy_client.response_code, 200) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
939 self.assertNotIn(get_obj(base_path, issue_closed_crit), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
940 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
941 self.assertIn(get_obj(base_path, issue_closed_norm), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
942 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
943 self.assertNotIn(get_obj(base_path, issue_open_crit), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
944 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
945 self.assertNotIn(get_obj(base_path, issue_open_norm), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
946 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
947 self.assertEqual(len(results['data']['collection']), 1) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
948 |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
949 # Retrieve all issues with word closed in title |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
950 form = cgi.FieldStorage() |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
951 form.list = [ |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
952 cgi.MiniFieldStorage('title', 'closed'), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
953 ] |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
954 results = self.server.get_collection('issue', form) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
955 self.assertEqual(self.dummy_client.response_code, 200) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
956 self.assertIn(get_obj(base_path, issue_closed_crit), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
957 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
958 self.assertIn(get_obj(base_path, issue_closed_norm), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
959 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
960 self.assertNotIn(get_obj(base_path, issue_open_crit), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
961 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
962 self.assertNotIn(get_obj(base_path, issue_open_norm), |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
963 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
964 self.assertEqual(len(results['data']['collection']), 2) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
965 |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
966 def testPagination(self): |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
967 """ |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
968 Test pagination. page_size is required and is an integer |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
969 starting at 1. page_index is optional and is an integer |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
970 starting at 1. Verify that pagination links are present |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
971 if paging, @total_size and X-Count-Total header match |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
972 number of items. |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
973 """ |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
974 # create sample data |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
975 for i in range(0, random.randint(8,15)): |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
976 self.db.issue.create(title='foo' + str(i)) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
977 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
978 # Retrieving all the issues |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
979 results = self.server.get_collection('issue', self.empty_form) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
980 self.assertEqual(self.dummy_client.response_code, 200) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
981 total_length = len(results['data']['collection']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
982 # Verify no pagination links if paging not used |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
983 self.assertFalse('@links' in results['data']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
984 self.assertEqual(results['data']['@total_size'], total_length) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
985 self.assertEqual( |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
986 self.dummy_client.additional_headers["X-Count-Total"], |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
987 str(total_length) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
988 ) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
989 |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
990 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
991 # Pagination will be 45% of the total result |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
992 # So 2 full pages and 1 partial page. |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
993 page_size = total_length * 45 // 100 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
994 page_one_expected = page_size |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
995 page_two_expected = page_size |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
996 page_three_expected = total_length - (2*page_one_expected) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
997 base_url="http://tracker.example/cgi-bin/roundup.cgi/" \ |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
998 "bugs/rest/data/issue" |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
999 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1000 # Retrieve page 1 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1001 form = cgi.FieldStorage() |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1002 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1003 cgi.MiniFieldStorage('@page_size', page_size), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1004 cgi.MiniFieldStorage('@page_index', 1) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1005 ] |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1006 results = self.server.get_collection('issue', form) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1007 self.assertEqual(self.dummy_client.response_code, 200) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1008 self.assertEqual(len(results['data']['collection']), |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1009 page_one_expected) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1010 self.assertTrue('@links' in results['data']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1011 self.assertTrue('self' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1012 self.assertTrue('next' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1013 self.assertFalse('prev' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1014 self.assertEqual(results['data']['@links']['self'][0]['uri'], |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1015 "%s?@page_index=1&@page_size=%s"%(base_url,page_size)) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1016 self.assertEqual(results['data']['@links']['next'][0]['uri'], |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1017 "%s?@page_index=2&@page_size=%s"%(base_url,page_size)) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1018 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1019 page_one_results = results # save this for later |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1020 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1021 # Retrieve page 2 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1022 form = cgi.FieldStorage() |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1023 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1024 cgi.MiniFieldStorage('@page_size', page_size), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1025 cgi.MiniFieldStorage('@page_index', 2) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1026 ] |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1027 results = self.server.get_collection('issue', form) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1028 self.assertEqual(self.dummy_client.response_code, 200) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1029 self.assertEqual(len(results['data']['collection']), page_two_expected) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1030 self.assertTrue('@links' in results['data']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1031 self.assertTrue('self' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1032 self.assertTrue('next' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1033 self.assertTrue('prev' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1034 self.assertEqual(results['data']['@links']['self'][0]['uri'], |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1035 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue?@page_index=2&@page_size=%s"%page_size) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1036 self.assertEqual(results['data']['@links']['next'][0]['uri'], |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1037 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue?@page_index=3&@page_size=%s"%page_size) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1038 self.assertEqual(results['data']['@links']['prev'][0]['uri'], |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1039 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue?@page_index=1&@page_size=%s"%page_size) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1040 self.assertEqual(results['data']['@links']['self'][0]['rel'], |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1041 'self') |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1042 self.assertEqual(results['data']['@links']['next'][0]['rel'], |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1043 'next') |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1044 self.assertEqual(results['data']['@links']['prev'][0]['rel'], |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1045 'prev') |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
1046 |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1047 # Retrieve page 3 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1048 form = cgi.FieldStorage() |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1049 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1050 cgi.MiniFieldStorage('@page_size', page_size), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1051 cgi.MiniFieldStorage('@page_index', 3) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1052 ] |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1053 results = self.server.get_collection('issue', form) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1054 self.assertEqual(self.dummy_client.response_code, 200) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1055 self.assertEqual(len(results['data']['collection']), page_three_expected) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1056 self.assertTrue('@links' in results['data']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1057 self.assertTrue('self' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1058 self.assertFalse('next' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1059 self.assertTrue('prev' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1060 self.assertEqual(results['data']['@links']['self'][0]['uri'], |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1061 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue?@page_index=3&@page_size=%s"%page_size) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1062 self.assertEqual(results['data']['@links']['prev'][0]['uri'], |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1063 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue?@page_index=2&@page_size=%s"%page_size) |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1064 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1065 # Verify that page_index is optional |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1066 # Should start at page 1 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1067 form = cgi.FieldStorage() |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1068 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
1069 cgi.MiniFieldStorage('@page_size', page_size), |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1070 ] |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1071 results = self.server.get_collection('issue', form) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1072 self.assertEqual(self.dummy_client.response_code, 200) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1073 self.assertEqual(len(results['data']['collection']), page_size) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1074 self.assertTrue('@links' in results['data']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1075 self.assertTrue('self' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1076 self.assertTrue('next' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1077 self.assertFalse('prev' in results['data']['@links']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1078 self.assertEqual(page_one_results, results) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1079 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1080 # FIXME add tests for out of range once we decide what response |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1081 # is needed to: |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1082 # page_size < 0 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
1083 # page_index < 0 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1084 |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1085 def testRestRateLimit(self): |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1086 |
|
7555
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1087 calls_per_interval = 20 |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1088 interval_sec = 60 |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1089 wait_time_str = str(int(interval_sec/calls_per_interval)) |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1090 |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1091 self.db.config['WEB_API_CALLS_PER_INTERVAL'] = calls_per_interval |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1092 self.db.config['WEB_API_INTERVAL_IN_SEC'] = interval_sec |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1093 |
|
5733
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
1094 # Otk code never passes through the |
|
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
1095 # retry loop. Not sure why but I can force it |
|
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
1096 # through the loop by setting the internal _db_type |
|
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
1097 # setting once the db is created by the previous command. |
|
5734
5cd9ac3daed7
Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents:
5733
diff
changeset
|
1098 try: |
|
5cd9ac3daed7
Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents:
5733
diff
changeset
|
1099 self.db.Otk._db_type = whichdb("%s/%s"%(self.db.Otk.dir, self.db.Otk.name)) |
|
5cd9ac3daed7
Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents:
5733
diff
changeset
|
1100 except AttributeError: |
|
5cd9ac3daed7
Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents:
5733
diff
changeset
|
1101 # if dir attribute doesn't exist the primary db is not |
|
5cd9ac3daed7
Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents:
5733
diff
changeset
|
1102 # sqlite or anydbm. So don't need to exercise code. |
|
5cd9ac3daed7
Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents:
5733
diff
changeset
|
1103 pass |
|
5733
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
1104 |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
1105 start_time = utcnow() |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1106 # don't set an accept header; json should be the default |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1107 # use up all our allowed api calls |
|
7555
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1108 for i in range(calls_per_interval): |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1109 # i is 0 ... calls_per_interval |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1110 self.client_error_message = [] |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1111 self.server.client.env.update({'REQUEST_METHOD': 'GET'}) |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1112 results = self.server.dispatch('GET', |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1113 "/rest/data/user/%s/realname"%self.joeid, |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1114 self.empty_form) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1115 |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
1116 loop_time = utcnow() |
|
7555
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1117 self.assertLess((loop_time-start_time).total_seconds(), |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1118 int(wait_time_str), |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1119 "Test system is too slow to complete test as configured") |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1120 |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1121 # is successful |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1122 self.assertEqual(self.server.client.response_code, 200) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1123 # does not have Retry-After header as we have |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1124 # suceeded with this query |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1125 self.assertFalse("Retry-After" in |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1126 self.server.client.additional_headers) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1127 # remaining count is correct |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1128 self.assertEqual( |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1129 self.server.client.additional_headers["X-RateLimit-Remaining"], |
|
5937
5d0873a4de4a
fix rate limit headers - were ints/floats need to be strings
John Rouillard <rouilj@ieee.org>
parents:
5879
diff
changeset
|
1130 str(self.db.config['WEB_API_CALLS_PER_INTERVAL'] -1 - i) |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1131 ) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1132 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1133 # trip limit |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1134 self.server.client.additional_headers.clear() |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1135 results = self.server.dispatch('GET', |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1136 "/rest/data/user/%s/realname"%self.joeid, |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1137 self.empty_form) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1138 print(results) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1139 self.assertEqual(self.server.client.response_code, 429) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1140 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1141 self.assertEqual( |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1142 self.server.client.additional_headers["X-RateLimit-Limit"], |
|
5937
5d0873a4de4a
fix rate limit headers - were ints/floats need to be strings
John Rouillard <rouilj@ieee.org>
parents:
5879
diff
changeset
|
1143 str(self.db.config['WEB_API_CALLS_PER_INTERVAL'])) |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1144 self.assertEqual( |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1145 self.server.client.additional_headers["X-RateLimit-Limit-Period"], |
|
5937
5d0873a4de4a
fix rate limit headers - were ints/floats need to be strings
John Rouillard <rouilj@ieee.org>
parents:
5879
diff
changeset
|
1146 str(self.db.config['WEB_API_INTERVAL_IN_SEC'])) |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1147 self.assertEqual( |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1148 self.server.client.additional_headers["X-RateLimit-Remaining"], |
|
5937
5d0873a4de4a
fix rate limit headers - were ints/floats need to be strings
John Rouillard <rouilj@ieee.org>
parents:
5879
diff
changeset
|
1149 '0') |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1150 # value will be almost 60. Allow 1-2 seconds for all 20 rounds. |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1151 self.assertAlmostEqual( |
|
5937
5d0873a4de4a
fix rate limit headers - were ints/floats need to be strings
John Rouillard <rouilj@ieee.org>
parents:
5879
diff
changeset
|
1152 float(self.server.client.additional_headers["X-RateLimit-Reset"]), |
|
6660
32c6e98e5a21
Larger delta for X-RateLimit-Reset tests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6554
diff
changeset
|
1153 59, delta=5) |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1154 self.assertEqual( |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1155 str(self.server.client.additional_headers["Retry-After"]), |
|
7555
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1156 wait_time_str) # check as string |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1157 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1158 print("Reset:", self.server.client.additional_headers["X-RateLimit-Reset"]) |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
1159 print("Now realtime pre-sleep:", utcnow()) |
|
7555
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1160 # sleep as requested so we can do another login |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1161 sleep(float(wait_time_str) + 0.1) |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
1162 print("Now realtime post-sleep:", utcnow()) |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1163 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1164 # this should succeed |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1165 self.server.client.additional_headers.clear() |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1166 results = self.server.dispatch('GET', |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1167 "/rest/data/user/%s/realname"%self.joeid, |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1168 self.empty_form) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1169 print(results) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1170 print("Reset:", self.server.client.additional_headers["X-RateLimit-Reset-date"]) |
|
7587
8f29e4ea05ce
fix: issue2551278 - datetime.datetime.utcnow deprecation.
John Rouillard <rouilj@ieee.org>
parents:
7582
diff
changeset
|
1171 print("Now realtime:", utcnow()) |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1172 print("Now ts header:", self.server.client.additional_headers["Now"]) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1173 print("Now date header:", self.server.client.additional_headers["Now-date"]) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1174 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1175 self.assertEqual(self.server.client.response_code, 200) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1176 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1177 self.assertEqual( |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1178 self.server.client.additional_headers["X-RateLimit-Limit"], |
|
5937
5d0873a4de4a
fix rate limit headers - were ints/floats need to be strings
John Rouillard <rouilj@ieee.org>
parents:
5879
diff
changeset
|
1179 str(self.db.config['WEB_API_CALLS_PER_INTERVAL'])) |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1180 self.assertEqual( |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1181 self.server.client.additional_headers["X-RateLimit-Limit-Period"], |
|
5937
5d0873a4de4a
fix rate limit headers - were ints/floats need to be strings
John Rouillard <rouilj@ieee.org>
parents:
5879
diff
changeset
|
1182 str(self.db.config['WEB_API_INTERVAL_IN_SEC'])) |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1183 self.assertEqual( |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1184 self.server.client.additional_headers["X-RateLimit-Remaining"], |
|
5937
5d0873a4de4a
fix rate limit headers - were ints/floats need to be strings
John Rouillard <rouilj@ieee.org>
parents:
5879
diff
changeset
|
1185 '0') |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1186 self.assertFalse("Retry-After" in |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1187 self.server.client.additional_headers) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1188 # we still need to wait a minute for everything to clear |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1189 self.assertAlmostEqual( |
|
5937
5d0873a4de4a
fix rate limit headers - were ints/floats need to be strings
John Rouillard <rouilj@ieee.org>
parents:
5879
diff
changeset
|
1190 float(self.server.client.additional_headers["X-RateLimit-Reset"]), |
|
6660
32c6e98e5a21
Larger delta for X-RateLimit-Reset tests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6554
diff
changeset
|
1191 59, delta=5) |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1192 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1193 # and make sure we need to wait another three seconds |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1194 # as we consumed the last api call |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1195 results = self.server.dispatch('GET', |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1196 "/rest/data/user/%s/realname"%self.joeid, |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1197 self.empty_form) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1198 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1199 self.assertEqual(self.server.client.response_code, 429) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1200 self.assertEqual( |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1201 str(self.server.client.additional_headers["Retry-After"]), |
|
7555
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1202 wait_time_str) # check as string |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1203 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1204 json_dict = json.loads(b2s(results)) |
|
7555
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1205 self.assertEqual( |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1206 json_dict['error']['msg'], |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1207 "Api rate limits exceeded. Please wait: %s seconds." % |
|
451232f83244
test: Modify testRestRateLimit test to report when system is too slow.
John Rouillard <rouilj@ieee.org>
parents:
7389
diff
changeset
|
1208 wait_time_str) |
|
5732
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1209 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1210 # reset rest params |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1211 self.db.config['WEB_API_CALLS_PER_INTERVAL'] = 0 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1212 self.db.config['WEB_API_INTERVAL_IN_SEC'] = 3600 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1213 |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1214 def testEtagGeneration(self): |
|
5668
a4bb88a1a643
A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents:
5656
diff
changeset
|
1215 ''' Make sure etag generation is stable |
|
a4bb88a1a643
A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents:
5656
diff
changeset
|
1216 |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1217 This mocks date.Date() when creating the target to be |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1218 etagged. Differing dates make this test impossible. |
|
5668
a4bb88a1a643
A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents:
5656
diff
changeset
|
1219 ''' |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1220 from roundup import date |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1221 |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1222 originalDate = date.Date |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1223 |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1224 dummy=date.Date('2000-06-26.00:34:02.0') |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1225 |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1226 # is a closure the best way to return a static Date object?? |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1227 def dummyDate(adate=None): |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1228 def dummyClosure(adate=None, translator=None): |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1229 return dummy |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1230 return dummyClosure |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1231 |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1232 date.Date = dummyDate() |
|
5728
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1233 try: |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1234 newuser = self.db.user.create( |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1235 username='john', |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1236 password=password.Password('random1', scheme='plaintext'), |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1237 address='random1@home.org', |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1238 realname='JohnRandom', |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1239 roles='User,Admin' |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1240 ) |
|
5668
a4bb88a1a643
A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents:
5656
diff
changeset
|
1241 |
|
5728
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1242 # verify etag matches what we calculated in the past |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1243 node = self.db.user.getnode(newuser) |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1244 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY']) |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1245 items = node.items(protected=True) # include every item |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1246 print(repr(sorted(items))) |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1247 print(etag) |
|
6256
29c6dc8ed004
Test handling of unset transitive link field.
John Rouillard <rouilj@ieee.org>
parents:
6185
diff
changeset
|
1248 self.assertEqual(etag, '"07c3a7f214d394cf46220e294a5a53c8"') |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1249 |
|
5728
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1250 # modify key and verify we have a different etag |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1251 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY'] + "a") |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1252 items = node.items(protected=True) # include every item |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1253 print(repr(sorted(items))) |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1254 print(etag) |
|
6256
29c6dc8ed004
Test handling of unset transitive link field.
John Rouillard <rouilj@ieee.org>
parents:
6185
diff
changeset
|
1255 self.assertNotEqual(etag, '"07c3a7f214d394cf46220e294a5a53c8"') |
|
5668
a4bb88a1a643
A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents:
5656
diff
changeset
|
1256 |
|
5728
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1257 # change data and verify we have a different etag |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1258 node.username="Paul" |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1259 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY']) |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1260 items = node.items(protected=True) # include every item |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1261 print(repr(sorted(items))) |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1262 print(etag) |
|
6256
29c6dc8ed004
Test handling of unset transitive link field.
John Rouillard <rouilj@ieee.org>
parents:
6185
diff
changeset
|
1263 self.assertEqual(etag, '"d655801d3a6d51e32891531b06ccecfa"') |
|
5728
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1264 finally: |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1265 date.Date = originalDate |
|
5668
a4bb88a1a643
A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents:
5656
diff
changeset
|
1266 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1267 def testEtagProcessing(self): |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1268 ''' |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1269 Etags can come from two places: |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1270 If-Match http header |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1271 @etags value posted in the form |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1272 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1273 Both will be checked if availble. If either one |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1274 fails, the etag check will fail. |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1275 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1276 Run over header only, etag in form only, both, |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1277 each one broke and no etag. Use the put command |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1278 to trigger the etag checking code. |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1279 ''' |
|
6539
f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents:
6525
diff
changeset
|
1280 for mode in ('header', 'header-gzip', 'etag', 'etag-br', |
|
f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents:
6525
diff
changeset
|
1281 'both', 'brokenheader', 'brokenetag', 'none'): |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1282 try: |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1283 # clean up any old header |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1284 del(self.headers) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1285 except AttributeError: |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1286 pass |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1287 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1288 form = cgi.FieldStorage() |
|
5726
e199d0ae4a25
issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents:
5711
diff
changeset
|
1289 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1290 self.db.config['WEB_SECRET_KEY']) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1291 form.list = [ |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1292 cgi.MiniFieldStorage('data', 'Joe Doe Doe'), |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1293 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1294 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1295 if mode == 'header': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1296 print("Mode = %s"%mode) |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1297 self.headers = {'if-match': etag} |
|
6539
f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents:
6525
diff
changeset
|
1298 elif mode == 'header-gzip': |
|
f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents:
6525
diff
changeset
|
1299 print("Mode = %s"%mode) |
|
f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents:
6525
diff
changeset
|
1300 gzip_etag = etag[:-1] + "-gzip" + etag[-1:] |
|
f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents:
6525
diff
changeset
|
1301 self.headers = {'if-match': gzip_etag} |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1302 elif mode == 'etag': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1303 print("Mode = %s"%mode) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1304 form.list.append(cgi.MiniFieldStorage('@etag', etag)) |
|
6539
f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents:
6525
diff
changeset
|
1305 elif mode == 'etag-br': |
|
f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents:
6525
diff
changeset
|
1306 print("Mode = %s"%mode) |
|
f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents:
6525
diff
changeset
|
1307 br_etag = etag[:-1] + "-br" + etag[-1:] |
|
f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents:
6525
diff
changeset
|
1308 form.list.append(cgi.MiniFieldStorage('@etag', br_etag)) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1309 elif mode == 'both': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1310 print("Mode = %s"%mode) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1311 self.headers = {'etag': etag} |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1312 form.list.append(cgi.MiniFieldStorage('@etag', etag)) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1313 elif mode == 'brokenheader': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1314 print("Mode = %s"%mode) |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1315 self.headers = {'if-match': 'bad'} |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1316 form.list.append(cgi.MiniFieldStorage('@etag', etag)) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1317 elif mode == 'brokenetag': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1318 print("Mode = %s"%mode) |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1319 self.headers = {'if-match': etag} |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1320 form.list.append(cgi.MiniFieldStorage('@etag', 'bad')) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1321 elif mode == 'none': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1322 print( "Mode = %s"%mode) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1323 else: |
|
6539
f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents:
6525
diff
changeset
|
1324 self.fail("unknown mode '%s' found"%mode) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1325 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1326 results = self.server.put_attribute( |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1327 'user', self.joeid, 'realname', form |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1328 ) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1329 if mode not in ('brokenheader', 'brokenetag', 'none'): |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1330 self.assertEqual(self.dummy_client.response_code, 200) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1331 else: |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1332 self.assertEqual(self.dummy_client.response_code, 412) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1333 |
|
5993
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1334 def testBinaryFieldStorage(self): |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1335 ''' attempt to exercise all paths in the BinaryFieldStorage |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1336 class |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1337 ''' |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1338 |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1339 expected={ "data": { |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1340 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1", |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1341 "id": "1" |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1342 } |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1343 } |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1344 |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1345 body=b'{ "title": "Joe Doe has problems", \ |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1346 "nosy": [ "1", "3" ], \ |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1347 "assignedto": "2", \ |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1348 "abool": true, \ |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1349 "afloat": 2.3, \ |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1350 "anint": 567890 \ |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1351 }' |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1352 env = { "CONTENT_TYPE": "application/json", |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1353 "CONTENT_LENGTH": len(body), |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1354 "REQUEST_METHOD": "POST" |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1355 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1356 self.server.client.env.update(env) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1357 |
|
5993
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1358 headers={"accept": "application/json; version=1", |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1359 "content-type": env['CONTENT_TYPE'], |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1360 "content-length": env['CONTENT_LENGTH'], |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1361 } |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1362 self.headers=headers |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1363 # we need to generate a FieldStorage the looks like |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1364 # FieldStorage(None, None, 'string') rather than |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1365 # FieldStorage(None, None, []) |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1366 body_file=BytesIO(body) # FieldStorage needs a file |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1367 form = client.BinaryFieldStorage(body_file, |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1368 headers=headers, |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1369 environ=env) |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1370 self.server.client.request.headers.get=self.get_header |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1371 results = self.server.dispatch(env["REQUEST_METHOD"], |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1372 "/rest/data/issue", |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1373 form) |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1374 json_dict = json.loads(b2s(results)) |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1375 self.assertEqual(json_dict,expected) |
|
a0ab2c5d1c2a
Add test for BinaryFieldStorage.
John Rouillard <rouilj@ieee.org>
parents:
5987
diff
changeset
|
1376 |
|
7372
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1377 |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1378 def testDispatchGet(self): |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1379 self.create_sampledata() |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1380 |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1381 form = cgi.FieldStorage() |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1382 self.server.client.request.headers.get=self.get_header |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1383 |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1384 for item in [ "55", "issue1", "1" ]: |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1385 print("test item: '%s'" % item) |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1386 results = self.server.dispatch("GET", |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1387 "/rest/data/issue/%s" % item, |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1388 form) |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1389 json_dict = json.loads(b2s(results)) |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1390 try: |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1391 self.assertEqual(json_dict['error']['status'], 404) |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1392 except KeyError as e: |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1393 if e.args[0] == "error" and item == "1": |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1394 pass |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1395 else: |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1396 self.assertTrue(False) |
|
886a5c767d7e
Invalid REST item spec returns 404 rather than 400.
John Rouillard <rouilj@ieee.org>
parents:
7183
diff
changeset
|
1397 |
|
5690
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1398 def testDispatchPost(self): |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1399 """ |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1400 run POST through rest dispatch(). This also tests |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1401 sending json payload through code as dispatch is the |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1402 code that changes json payload into something we can |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1403 process. |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1404 """ |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1405 |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1406 # TEST #0 |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1407 # POST: issue make joe assignee and admin and demo as |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1408 # nosy |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1409 # simulate: /rest/data/issue |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1410 body=b'{ "title": "Joe Doe has problems", \ |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1411 "nosy": [ "1", "3" ], \ |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1412 "assignedto": "2", \ |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1413 "abool": true, \ |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1414 "afloat": 2.3, \ |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1415 "anint": 567890 \ |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1416 }' |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1417 env = { "CONTENT_TYPE": "application/json", |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1418 "CONTENT_LENGTH": len(body), |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1419 "REQUEST_METHOD": "POST" |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1420 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1421 self.server.client.env.update(env) |
|
5690
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1422 headers={"accept": "application/json; version=1", |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1423 "content-type": env['CONTENT_TYPE'], |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1424 "content-length": env['CONTENT_LENGTH'], |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1425 } |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1426 self.headers=headers |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1427 # we need to generate a FieldStorage the looks like |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1428 # FieldStorage(None, None, 'string') rather than |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1429 # FieldStorage(None, None, []) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1430 body_file=BytesIO(body) # FieldStorage needs a file |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1431 form = client.BinaryFieldStorage(body_file, |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1432 headers=headers, |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1433 environ=env) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1434 self.server.client.request.headers.get=self.get_header |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1435 results = self.server.dispatch(env["REQUEST_METHOD"], |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1436 "/rest/data/issue", |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1437 form) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1438 |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1439 print(results) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1440 self.assertEqual(self.server.client.response_code, 201) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1441 json_dict = json.loads(b2s(results)) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1442 self.assertEqual(json_dict['data']['link'], |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1443 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1") |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1444 self.assertEqual(json_dict['data']['id'], "1") |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1445 self.server.client.env.update({'REQUEST_METHOD': 'GET'}) |
|
5690
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1446 results = self.server.dispatch('GET', |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1447 "/rest/data/issue/1", self.empty_form) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1448 print(results) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1449 json_dict = json.loads(b2s(results)) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1450 self.assertEqual(json_dict['data']['link'], |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1451 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1") |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1452 self.assertEqual(json_dict['data']['attributes']['abool'], True) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1453 self.assertEqual(json_dict['data']['attributes']['afloat'], 2.3) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1454 self.assertEqual(json_dict['data']['attributes']['anint'], 567890) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1455 self.assertEqual(len(json_dict['data']['attributes']['nosy']), 3) |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1456 self.assertEqual(json_dict['data']['attributes']\ |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1457 ['assignedto']['link'], |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1458 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/2") |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1459 |
|
6317
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1460 |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1461 def testDispatchDelete(self): |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1462 """ |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1463 run Delete through rest dispatch(). |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1464 """ |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1465 |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1466 # TEST #0 |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1467 # Delete class raises unauthorized error |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1468 # simulate: /rest/data/issue |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1469 env = { "REQUEST_METHOD": "DELETE" |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1470 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1471 self.server.client.env.update(env) |
|
6317
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1472 headers={"accept": "application/json; version=1", |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1473 } |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1474 self.headers=headers |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1475 self.server.client.request.headers.get=self.get_header |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1476 results = self.server.dispatch(env["REQUEST_METHOD"], |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1477 "/rest/data/issue", |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1478 self.empty_form) |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1479 |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1480 print(results) |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1481 self.assertEqual(self.server.client.response_code, 403) |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1482 json_dict = json.loads(b2s(results)) |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1483 |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1484 self.assertEqual(json_dict['error']['msg'], |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1485 "Deletion of a whole class disabled") |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1486 |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
1487 |
|
6311
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1488 def testDispatchBadContent(self): |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1489 """ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1490 runthrough rest dispatch() with bad content_type patterns. |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1491 """ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1492 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1493 # simulate: /rest/data/issue |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1494 body=b'{ "title": "Joe Doe has problems", \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1495 "nosy": [ "1", "3" ], \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1496 "assignedto": "2", \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1497 "abool": true, \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1498 "afloat": 2.3, \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1499 "anint": 567890 \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1500 }' |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1501 env = { "CONTENT_TYPE": "application/jzot", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1502 "CONTENT_LENGTH": len(body), |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1503 "REQUEST_METHOD": "POST" |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1504 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1505 self.server.client.env.update(env) |
|
6311
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1506 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1507 headers={"accept": "application/json; version=1", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1508 "content-type": env['CONTENT_TYPE'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1509 "content-length": env['CONTENT_LENGTH'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1510 } |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1511 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1512 self.headers=headers |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1513 # we need to generate a FieldStorage the looks like |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1514 # FieldStorage(None, None, 'string') rather than |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1515 # FieldStorage(None, None, []) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1516 body_file=BytesIO(body) # FieldStorage needs a file |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1517 form = client.BinaryFieldStorage(body_file, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1518 headers=headers, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1519 environ=env) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1520 self.server.client.request.headers.get=self.get_header |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1521 results = self.server.dispatch(env["REQUEST_METHOD"], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1522 "/rest/data/issue", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1523 form) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1524 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1525 print(results) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1526 self.assertEqual(self.server.client.response_code, 415) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1527 json_dict = json.loads(b2s(results)) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1528 self.assertEqual(json_dict['error']['msg'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1529 "Unable to process input of type application/jzot") |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1530 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1531 # Test GET as well. I am not sure if this should pass or not. |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1532 # Arguably GET doesn't use any form/json input but.... |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1533 results = self.server.dispatch('GET', |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1534 "/rest/data/issue", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1535 form) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1536 print(results) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1537 self.assertEqual(self.server.client.response_code, 415) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1538 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1539 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1540 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1541 def testDispatchBadAccept(self): |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1542 # simulate: /rest/data/issue expect failure unknown accept settings |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1543 body=b'{ "title": "Joe Doe has problems", \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1544 "nosy": [ "1", "3" ], \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1545 "assignedto": "2", \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1546 "abool": true, \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1547 "afloat": 2.3, \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1548 "anint": 567890 \ |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1549 }' |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1550 env = { "CONTENT_TYPE": "application/json", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1551 "CONTENT_LENGTH": len(body), |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1552 "REQUEST_METHOD": "POST" |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1553 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1554 self.server.client.env.update(env) |
|
6311
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1555 headers={"accept": "application/zot; version=1; q=0.5", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1556 "content-type": env['CONTENT_TYPE'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1557 "content-length": env['CONTENT_LENGTH'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1558 } |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1559 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1560 self.headers=headers |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1561 # we need to generate a FieldStorage the looks like |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1562 # FieldStorage(None, None, 'string') rather than |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1563 # FieldStorage(None, None, []) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1564 body_file=BytesIO(body) # FieldStorage needs a file |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1565 form = client.BinaryFieldStorage(body_file, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1566 headers=headers, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1567 environ=env) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1568 self.server.client.request.headers.get=self.get_header |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1569 results = self.server.dispatch(env["REQUEST_METHOD"], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1570 "/rest/data/issue", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1571 form) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1572 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1573 print(results) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1574 self.assertEqual(self.server.client.response_code, 406) |
|
6312
6ef7b66774b4
Fix test. Env without xml fails due to added ,
John Rouillard <rouilj@ieee.org>
parents:
6311
diff
changeset
|
1575 self.assertIn(b"Requested content type 'application/zot; version=1; q=0.5' is not available.\nAcceptable types: */*, application/json", results) |
|
6311
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1576 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1577 # simulate: /rest/data/issue works, multiple acceptable output, one |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1578 # is valid |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1579 env = { "CONTENT_TYPE": "application/json", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1580 "CONTENT_LENGTH": len(body), |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1581 "REQUEST_METHOD": "POST" |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1582 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1583 self.server.client.env.update(env) |
|
6311
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1584 headers={"accept": "application/zot; version=1; q=0.75, " |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1585 "application/json; version=1; q=0.5", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1586 "content-type": env['CONTENT_TYPE'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1587 "content-length": env['CONTENT_LENGTH'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1588 } |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1589 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1590 self.headers=headers |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1591 # we need to generate a FieldStorage the looks like |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1592 # FieldStorage(None, None, 'string') rather than |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1593 # FieldStorage(None, None, []) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1594 body_file=BytesIO(body) # FieldStorage needs a file |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1595 form = client.BinaryFieldStorage(body_file, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1596 headers=headers, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1597 environ=env) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1598 self.server.client.request.headers.get=self.get_header |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1599 results = self.server.dispatch(env["REQUEST_METHOD"], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1600 "/rest/data/issue", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1601 form) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1602 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1603 print(results) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1604 self.assertEqual(self.server.client.response_code, 201) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1605 json_dict = json.loads(b2s(results)) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1606 # ERROR this should be 1. What's happening is that the code |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1607 # for handling 406 error code runs through everything and creates |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1608 # the item. Then it throws a 406 after the work is done when it |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1609 # realizes it can't respond as requested. So the 406 post above |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1610 # creates issue 1 and this one creates issue 2. |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1611 self.assertEqual(json_dict['data']['id'], "2") |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1612 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1613 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1614 # test 3 accept is empty. This triggers */* so passes |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1615 headers={"accept": "", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1616 "content-type": env['CONTENT_TYPE'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1617 "content-length": env['CONTENT_LENGTH'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1618 } |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1619 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1620 self.headers=headers |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1621 # we need to generate a FieldStorage the looks like |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1622 # FieldStorage(None, None, 'string') rather than |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1623 # FieldStorage(None, None, []) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1624 body_file=BytesIO(body) # FieldStorage needs a file |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1625 form = client.BinaryFieldStorage(body_file, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1626 headers=headers, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1627 environ=env) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1628 self.server.client.request.headers.get=self.get_header |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1629 results = self.server.dispatch(env["REQUEST_METHOD"], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1630 "/rest/data/issue", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1631 form) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1632 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1633 print(results) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1634 self.assertEqual(self.server.client.response_code, 201) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1635 json_dict = json.loads(b2s(results)) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1636 # This is one more than above. Will need to be fixed |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1637 # When error above is fixed. |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1638 self.assertEqual(json_dict['data']['id'], "3") |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1639 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1640 # test 4 accept is random junk. |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1641 headers={"accept": "Xyzzy I am not a mime, type;", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1642 "content-type": env['CONTENT_TYPE'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1643 "content-length": env['CONTENT_LENGTH'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1644 } |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1645 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1646 self.headers=headers |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1647 # we need to generate a FieldStorage the looks like |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1648 # FieldStorage(None, None, 'string') rather than |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1649 # FieldStorage(None, None, []) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1650 body_file=BytesIO(body) # FieldStorage needs a file |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1651 form = client.BinaryFieldStorage(body_file, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1652 headers=headers, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1653 environ=env) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1654 self.server.client.request.headers.get=self.get_header |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1655 results = self.server.dispatch(env["REQUEST_METHOD"], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1656 "/rest/data/issue", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1657 form) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1658 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1659 print(results) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1660 self.assertEqual(self.server.client.response_code, 406) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1661 json_dict = json.loads(b2s(results)) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1662 self.assertIn('Unable to parse Accept Header. Invalid media type: Xyzzy I am not a mime. Acceptable types: */* application/json', json_dict['error']['msg']) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1663 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1664 # test 5 accept mimetype is ok, param is not |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1665 headers={"accept": "*/*; foo", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1666 "content-type": env['CONTENT_TYPE'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1667 "content-length": env['CONTENT_LENGTH'], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1668 } |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1669 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1670 self.headers=headers |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1671 # we need to generate a FieldStorage the looks like |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1672 # FieldStorage(None, None, 'string') rather than |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1673 # FieldStorage(None, None, []) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1674 body_file=BytesIO(body) # FieldStorage needs a file |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1675 form = client.BinaryFieldStorage(body_file, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1676 headers=headers, |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1677 environ=env) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1678 self.server.client.request.headers.get=self.get_header |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1679 results = self.server.dispatch(env["REQUEST_METHOD"], |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1680 "/rest/data/issue", |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1681 form) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1682 |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1683 print(results) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1684 self.assertEqual(self.server.client.response_code, 406) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1685 json_dict = json.loads(b2s(results)) |
|
be8d5a8e090a
Fix uncaught error when parsing rest headers, document
John Rouillard <rouilj@ieee.org>
parents:
6256
diff
changeset
|
1686 self.assertIn('Unable to parse Accept Header. Invalid param: foo. Acceptable types: */* application/json', json_dict['error']['msg']) |
|
5690
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1687 |
|
6185
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1688 def testStatsGen(self): |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1689 # check stats being returned by put and get ops |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1690 # using dispatch which parses the @stats query param |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1691 |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1692 # find correct py2/py3 list comparison ignoring order |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1693 try: |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1694 list_test = self.assertCountEqual # py3 |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1695 except AttributeError: |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1696 list_test = self.assertItemsEqual # py2.7+ |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1697 |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1698 # get stats |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1699 form = cgi.FieldStorage() |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1700 form.list = [ |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1701 cgi.MiniFieldStorage('@stats', 'True'), |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1702 ] |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1703 results = self.server.dispatch('GET', |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1704 "/rest/data/user/1/realname", |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1705 form) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1706 self.assertEqual(self.dummy_client.response_code, 200) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1707 json_dict = json.loads(b2s(results)) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1708 |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1709 # check that @stats are defined |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1710 self.assertTrue( '@stats' in json_dict['data'] ) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1711 # check that the keys are present |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1712 # not validating values as that changes |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1713 valid_fields= [ us2u('elapsed'), |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1714 us2u('cache_hits'), |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1715 us2u('cache_misses'), |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1716 us2u('get_items'), |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1717 us2u('filtering') ] |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1718 list_test(valid_fields,json_dict['data']['@stats'].keys()) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1719 |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1720 # Make sure false value works to suppress @stats |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1721 form = cgi.FieldStorage() |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1722 form.list = [ |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1723 cgi.MiniFieldStorage('@stats', 'False'), |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1724 ] |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1725 self.server.client.env.update({'REQUEST_METHOD': 'GET'}) |
|
6185
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1726 results = self.server.dispatch('GET', |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1727 "/rest/data/user/1/realname", |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1728 form) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1729 self.assertEqual(self.dummy_client.response_code, 200) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1730 json_dict = json.loads(b2s(results)) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1731 print(results) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1732 # check that @stats are not defined |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1733 self.assertTrue( '@stats' not in json_dict['data'] ) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1734 |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1735 # Make sure non-true value works to suppress @stats |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1736 # false will always work |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1737 form = cgi.FieldStorage() |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1738 form.list = [ |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1739 cgi.MiniFieldStorage('@stats', 'random'), |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1740 ] |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1741 results = self.server.dispatch('GET', |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1742 "/rest/data/user/1/realname", |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1743 form) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1744 self.assertEqual(self.dummy_client.response_code, 200) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1745 json_dict = json.loads(b2s(results)) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1746 print(results) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1747 # check that @stats are not defined |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1748 self.assertTrue( '@stats' not in json_dict['data'] ) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1749 |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1750 # if @stats is not defined there should be no stats |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1751 results = self.server.dispatch('GET', |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1752 "/rest/data/user/1/realname", |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1753 self.empty_form) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1754 self.assertEqual(self.dummy_client.response_code, 200) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1755 json_dict = json.loads(b2s(results)) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1756 |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1757 # check that @stats are not defined |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1758 self.assertTrue( '@stats' not in json_dict['data'] ) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1759 |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1760 |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1761 |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1762 # change admin's realname via a normal web form |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1763 # This generates a FieldStorage that looks like: |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1764 # FieldStorage(None, None, []) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1765 # use etag from header |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1766 # |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1767 # Also use GET on the uri via the dispatch to retrieve |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1768 # the results from the db. |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1769 etag = calculate_etag(self.db.user.getnode('1'), |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1770 self.db.config['WEB_SECRET_KEY']) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1771 headers={"if-match": etag, |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1772 "accept": "application/vnd.json.test-v1+json", |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1773 } |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1774 form = cgi.FieldStorage() |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1775 form.list = [ |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1776 cgi.MiniFieldStorage('data', 'Joe Doe'), |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1777 cgi.MiniFieldStorage('@apiver', '1'), |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1778 cgi.MiniFieldStorage('@stats', 'true'), |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1779 ] |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1780 self.headers = headers |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1781 self.server.client.request.headers.get = self.get_header |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1782 self.db.setCurrentUser('admin') # must be admin to change user |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1783 self.server.client.env.update({'REQUEST_METHOD': 'PUT'}) |
|
6185
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1784 results = self.server.dispatch('PUT', |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1785 "/rest/data/user/1/realname", |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1786 form) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1787 self.assertEqual(self.dummy_client.response_code, 200) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1788 json_dict = json.loads(b2s(results)) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1789 list_test(valid_fields,json_dict['data']['@stats'].keys()) |
|
1cb2375015f0
Enable timing stats reporting in REST interface.
John Rouillard <rouilj@ieee.org>
parents:
6090
diff
changeset
|
1790 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1791 def testDispatch(self): |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1792 """ |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1793 run changes through rest dispatch(). This also tests |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1794 sending json payload through code as dispatch is the |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1795 code that changes json payload into something we can |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1796 process. |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1797 """ |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1798 # TEST #1 |
|
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1799 # PUT: joe's 'realname' using json data. |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1800 # simulate: /rest/data/user/<id>/realname |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1801 # use etag in header |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1802 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1803 self.db.config['WEB_SECRET_KEY']) |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1804 body=b'{ "data": "Joe Doe 1" }' |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1805 env = { "CONTENT_TYPE": "application/json", |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1806 "CONTENT_LENGTH": len(body), |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1807 "REQUEST_METHOD": "PUT", |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1808 "HTTP_ORIGIN": "https://invalid.origin" |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1809 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1810 self.server.client.env.update(env) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1811 |
|
5686
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1812 headers={"accept": "application/json; version=1", |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1813 "content-type": env['CONTENT_TYPE'], |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1814 "content-length": env['CONTENT_LENGTH'], |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1815 "if-match": etag |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1816 } |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1817 self.headers=headers |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1818 # we need to generate a FieldStorage the looks like |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1819 # FieldStorage(None, None, 'string') rather than |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1820 # FieldStorage(None, None, []) |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1821 body_file=BytesIO(body) # FieldStorage needs a file |
|
5656
d26d2590cd8c
Implement different workaround for https://bugs.python.org/issue27777
John Rouillard <rouilj@ieee.org>
parents:
5655
diff
changeset
|
1822 form = client.BinaryFieldStorage(body_file, |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1823 headers=headers, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1824 environ=env) |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
1825 self.server.client.request.headers.get=self.get_header |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1826 results = self.server.dispatch('PUT', |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1827 "/rest/data/user/%s/realname"%self.joeid, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1828 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1829 |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1830 # invalid origin, no credentials allowed. |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1831 self.assertNotIn("Access-Control-Allow-Credentials", |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1832 self.server.client.additional_headers) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1833 self.assertEqual(self.server.client.response_code, 200) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1834 results = self.server.get_element('user', self.joeid, self.empty_form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1835 self.assertEqual(self.dummy_client.response_code, 200) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1836 self.assertEqual(results['data']['attributes']['realname'], |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1837 'Joe Doe 1') |
|
5686
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1838 |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1839 |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1840 # substitute the version with an unacceptable version |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1841 # and verify it returns 400 code. |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1842 self.headers["accept"] = "application/json; version=1.1" |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1843 body_file=BytesIO(body) # FieldStorage needs a file |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1844 form = client.BinaryFieldStorage(body_file, |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1845 headers=headers, |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1846 environ=env) |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1847 self.server.client.request.headers.get=self.get_header |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1848 results = self.server.dispatch('PUT', |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1849 "/rest/data/user/%s/realname"%self.joeid, |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1850 form) |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1851 self.assertEqual(self.server.client.response_code, 400) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1852 del(self.headers) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1853 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1854 # TEST #2 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1855 # Set joe's 'realname' using json data. |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1856 # simulate: /rest/data/user/<id>/realname |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1857 # use etag in payload |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1858 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1859 self.db.config['WEB_SECRET_KEY']) |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1860 etagb = etag.strip ('"') |
|
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1861 body=s2b('{ "@etag": "\\"%s\\"", "data": "Joe Doe 2" }'%etagb) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1862 env = { "CONTENT_TYPE": "application/json", |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1863 "CONTENT_LENGTH": len(body), |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1864 "REQUEST_METHOD": "PUT", |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1865 } |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1866 self.headers=None # have FieldStorage get len from env. |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1867 body_file=BytesIO(body) # FieldStorage needs a file |
|
5656
d26d2590cd8c
Implement different workaround for https://bugs.python.org/issue27777
John Rouillard <rouilj@ieee.org>
parents:
5655
diff
changeset
|
1868 form = client.BinaryFieldStorage(body_file, |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1869 headers=None, |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1870 environ=env) |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
1871 self.server.client.request.headers.get=self.get_header |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1872 |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1873 headers={"accept": "application/json", |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1874 "content-type": env['CONTENT_TYPE'], |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1875 "if-match": etag |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1876 } |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1877 self.headers=headers # set for dispatch |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1878 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1879 results = self.server.dispatch('PUT', |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1880 "/rest/data/user/%s/realname"%self.joeid, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1881 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1882 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1883 self.assertEqual(self.server.client.response_code, 200) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1884 results = self.server.get_element('user', self.joeid, self.empty_form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1885 self.assertEqual(self.dummy_client.response_code, 200) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1886 self.assertEqual(results['data']['attributes']['realname'], |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1887 'Joe Doe 2') |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1888 del(self.headers) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1889 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1890 # TEST #3 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1891 # change Joe's realname via a normal web form |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1892 # This generates a FieldStorage that looks like: |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1893 # FieldStorage(None, None, []) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1894 # use etag from header |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1895 # |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1896 # Also use GET on the uri via the dispatch to retrieve |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1897 # the results from the db. |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1898 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1899 self.db.config['WEB_SECRET_KEY']) |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1900 headers={"if-match": etag, |
|
5686
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1901 "accept": "application/vnd.json.test-v1+json", |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1902 } |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1903 form = cgi.FieldStorage() |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1904 form.list = [ |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1905 cgi.MiniFieldStorage('data', 'Joe Doe'), |
|
5686
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1906 cgi.MiniFieldStorage('@apiver', '1'), |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1907 ] |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1908 self.headers = headers |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
1909 self.server.client.request.headers.get = self.get_header |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1910 results = self.server.dispatch('PUT', |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1911 "/rest/data/user/%s/realname"%self.joeid, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1912 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1913 self.assertEqual(self.dummy_client.response_code, 200) |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1914 self.server.client.env.update({'REQUEST_METHOD': "GET"}) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1915 results = self.server.dispatch('GET', |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1916 "/rest/data/user/%s/realname"%self.joeid, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1917 self.empty_form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1918 self.assertEqual(self.dummy_client.response_code, 200) |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1919 json_dict = json.loads(b2s(results)) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1920 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1921 self.assertEqual(json_dict['data']['data'], 'Joe Doe') |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1922 self.assertEqual(json_dict['data']['link'], |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1923 "http://tracker.example/cgi-bin/" |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1924 "roundup.cgi/bugs/rest/data/user/3/realname") |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1925 self.assertIn(json_dict['data']['type'], ("<class 'str'>", |
|
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1926 "<type 'str'>")) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1927 self.assertEqual(json_dict['data']["id"], "3") |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1928 del(self.headers) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1929 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1930 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1931 # TEST #4 |
|
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1932 # PATCH: joe's email address with json |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1933 # save address so we can use it later |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1934 stored_results = self.server.get_element('user', self.joeid, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1935 self.empty_form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1936 self.assertEqual(self.dummy_client.response_code, 200) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1937 |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1938 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1939 self.db.config['WEB_SECRET_KEY']) |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1940 etagb = etag.strip ('"') |
|
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1941 body=s2b('{ "address": "demo2@example.com", "@etag": "\\"%s\\""}'%etagb) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1942 env = { "CONTENT_TYPE": "application/json", |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1943 "CONTENT_LENGTH": len(body), |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1944 "REQUEST_METHOD": "PATCH" |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1945 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
1946 self.server.client.env.update(env) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1947 headers={"accept": "application/json", |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1948 "content-type": env['CONTENT_TYPE'], |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1949 "content-length": len(body) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1950 } |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1951 self.headers=headers |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1952 body_file=BytesIO(body) # FieldStorage needs a file |
|
5656
d26d2590cd8c
Implement different workaround for https://bugs.python.org/issue27777
John Rouillard <rouilj@ieee.org>
parents:
5655
diff
changeset
|
1953 form = client.BinaryFieldStorage(body_file, |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1954 headers=headers, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1955 environ=env) |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
1956 self.server.client.request.headers.get=self.get_header |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1957 results = self.server.dispatch('PATCH', |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1958 "/rest/data/user/%s"%self.joeid, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1959 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1960 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1961 self.assertEqual(self.server.client.response_code, 200) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1962 results = self.server.get_element('user', self.joeid, self.empty_form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1963 self.assertEqual(self.dummy_client.response_code, 200) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1964 self.assertEqual(results['data']['attributes']['address'], |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1965 'demo2@example.com') |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1966 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1967 # and set it back reusing env and headers from last test |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1968 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1969 self.db.config['WEB_SECRET_KEY']) |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1970 etagb = etag.strip ('"') |
|
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1971 body=s2b('{ "address": "%s", "@etag": "\\"%s\\""}'%( |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1972 stored_results['data']['attributes']['address'], |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1973 etagb)) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1974 # reuse env and headers from prior test. |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1975 body_file=BytesIO(body) # FieldStorage needs a file |
|
5656
d26d2590cd8c
Implement different workaround for https://bugs.python.org/issue27777
John Rouillard <rouilj@ieee.org>
parents:
5655
diff
changeset
|
1976 form = client.BinaryFieldStorage(body_file, |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1977 headers=headers, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1978 environ=env) |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
1979 self.server.client.request.headers.get=self.get_header |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1980 results = self.server.dispatch('PATCH', |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1981 "/rest/data/user/%s"%self.joeid, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1982 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1983 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1984 self.assertEqual(self.server.client.response_code, 200) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1985 results = self.server.get_element('user', self.joeid, self.empty_form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1986 self.assertEqual(self.dummy_client.response_code, 200) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1987 self.assertEqual(results['data']['attributes']['address'], |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1988 'random@home.org') |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1989 del(self.headers) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1990 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1991 # TEST #5 |
|
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1992 # POST: create new issue |
|
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1993 # no etag needed |
|
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1994 etag = "not needed" |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1995 body=b'{ "title": "foo bar", "priority": "critical" }' |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1996 env = { "CONTENT_TYPE": "application/json", |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1997 "CONTENT_LENGTH": len(body), |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1998 "REQUEST_METHOD": "POST" |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1999 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2000 self.server.client.env.update(env) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2001 headers={"accept": "application/json", |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
2002 "content-type": env['CONTENT_TYPE'], |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
2003 "content-length": len(body) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2004 } |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2005 self.headers=headers |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
2006 body_file=BytesIO(body) # FieldStorage needs a file |
|
5656
d26d2590cd8c
Implement different workaround for https://bugs.python.org/issue27777
John Rouillard <rouilj@ieee.org>
parents:
5655
diff
changeset
|
2007 form = client.BinaryFieldStorage(body_file, |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2008 headers=headers, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2009 environ=env) |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
2010 self.server.client.request.headers.get=self.get_header |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2011 results = self.server.dispatch('POST', |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2012 "/rest/data/issue", |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2013 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2014 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2015 self.assertEqual(self.server.client.response_code, 201) |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
2016 json_dict = json.loads(b2s(results)) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2017 issue_id=json_dict['data']['id'] |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2018 results = self.server.get_element('issue', |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2019 str(issue_id), # must be a string not unicode |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2020 self.empty_form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2021 self.assertEqual(self.dummy_client.response_code, 200) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2022 self.assertEqual(results['data']['attributes']['title'], |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2023 'foo bar') |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
2024 |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2025 # TEST #6 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2026 # POST: an invalid class |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2027 # no etag needed |
|
5710
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2028 etag = "not needed" |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2029 body=b'{ "title": "foo bar", "priority": "critical" }' |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2030 env = { "CONTENT_TYPE": "application/json", |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2031 "CONTENT_LENGTH": len(body), |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2032 "REQUEST_METHOD": "POST" |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2033 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2034 self.server.client.env.update(env) |
|
5710
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2035 headers={"accept": "application/json", |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2036 "content-type": env['CONTENT_TYPE'], |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2037 "content-length": len(body) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2038 } |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2039 self.headers=headers |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2040 body_file=BytesIO(body) # FieldStorage needs a file |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2041 form = client.BinaryFieldStorage(body_file, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2042 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2043 environ=env) |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2044 self.server.client.request.headers.get=self.get_header |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2045 results = self.server.dispatch('POST', |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2046 "/rest/data/nonissue", |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2047 form) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2048 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2049 self.assertEqual(self.server.client.response_code, 404) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2050 json_dict = json.loads(b2s(results)) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2051 status=json_dict['error']['status'] |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2052 msg=json_dict['error']['msg'] |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2053 self.assertEqual(status, 404) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2054 self.assertEqual(msg, 'Class nonissue not found') |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2055 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2056 # TEST #7 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2057 # POST: status without key field of name |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2058 # also test that version spec in accept header is accepted |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2059 # no etag needed |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2060 etag = "not needed" |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2061 body=b'{ "order": 5 }' |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2062 env = { "CONTENT_TYPE": "application/json", |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2063 "CONTENT_LENGTH": len(body), |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2064 "REQUEST_METHOD": "POST" |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2065 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2066 self.server.client.env.update(env) |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2067 headers={"accept": "application/json; version=1", |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2068 "content-type": env['CONTENT_TYPE'], |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2069 "content-length": len(body) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2070 } |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2071 self.headers=headers |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2072 body_file=BytesIO(body) # FieldStorage needs a file |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2073 form = client.BinaryFieldStorage(body_file, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2074 headers=headers, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2075 environ=env) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2076 self.server.client.request.headers.get=self.get_header |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2077 self.db.setCurrentUser('admin') # must be admin to create status |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2078 results = self.server.dispatch('POST', |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2079 "/rest/data/status", |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2080 form) |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2081 self.server.client.env.update(env) |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2082 self.assertEqual(self.server.client.response_code, 400) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2083 json_dict = json.loads(b2s(results)) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2084 status=json_dict['error']['status'] |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2085 msg=json_dict['error']['msg'] |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2086 self.assertEqual(status, 400) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2087 self.assertEqual(msg, "Must provide the 'name' property.") |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2088 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2089 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2090 # TEST #8 |
|
5984
25a813415d59
issue2551069 - when unsupported type is found report type
John Rouillard <rouilj@ieee.org>
parents:
5937
diff
changeset
|
2091 # DELETE: delete issue 1 also test return type by extension |
|
25a813415d59
issue2551069 - when unsupported type is found report type
John Rouillard <rouilj@ieee.org>
parents:
5937
diff
changeset
|
2092 # test bogus extension as well. |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2093 etag = calculate_etag(self.db.issue.getnode("1"), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2094 self.db.config['WEB_SECRET_KEY']) |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2095 etagb = etag.strip ('"') |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2096 env = {"CONTENT_TYPE": "application/json", |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2097 "CONTENT_LEN": 0, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2098 "REQUEST_METHOD": "DELETE" } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2099 self.server.client.env.update(env) |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2100 # use text/plain header and request json output by appending |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2101 # .json to the url. |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2102 headers={"accept": "text/plain", |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2103 "content-type": env['CONTENT_TYPE'], |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2104 "if-match": '"%s"'%etagb, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2105 "content-length": 0, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2106 } |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2107 self.headers=headers |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2108 body_file=BytesIO(b'') # FieldStorage needs a file |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2109 form = client.BinaryFieldStorage(body_file, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2110 headers=headers, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2111 environ=env) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2112 self.server.client.request.headers.get=self.get_header |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2113 self.db.setCurrentUser('admin') # must be admin to delete issue |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2114 results = self.server.dispatch('DELETE', |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2115 "/rest/data/issue/1.json", |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2116 form) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2117 self.assertEqual(self.server.client.response_code, 200) |
|
5984
25a813415d59
issue2551069 - when unsupported type is found report type
John Rouillard <rouilj@ieee.org>
parents:
5937
diff
changeset
|
2118 print(results) |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2119 json_dict = json.loads(b2s(results)) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2120 status=json_dict['data']['status'] |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2121 self.assertEqual(status, 'ok') |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2122 |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2123 self.server.client.env.update({'REQUEST_METHOD': 'GET'}) |
|
5986
8b88fb789208
still trying to get testing to pass.
John Rouillard <rouilj@ieee.org>
parents:
5985
diff
changeset
|
2124 results = self.server.dispatch('GET', |
|
8b88fb789208
still trying to get testing to pass.
John Rouillard <rouilj@ieee.org>
parents:
5985
diff
changeset
|
2125 "/rest/data/issuetitle:=asdf.jon", |
|
5984
25a813415d59
issue2551069 - when unsupported type is found report type
John Rouillard <rouilj@ieee.org>
parents:
5937
diff
changeset
|
2126 form) |
|
25a813415d59
issue2551069 - when unsupported type is found report type
John Rouillard <rouilj@ieee.org>
parents:
5937
diff
changeset
|
2127 self.assertEqual(self.server.client.response_code, 406) |
|
25a813415d59
issue2551069 - when unsupported type is found report type
John Rouillard <rouilj@ieee.org>
parents:
5937
diff
changeset
|
2128 print(results) |
|
5985
f1191a470598
Fix test to account for mixxing dicttoxml.
John Rouillard <rouilj@ieee.org>
parents:
5984
diff
changeset
|
2129 try: # only verify local copy not system installed copy |
|
f1191a470598
Fix test to account for mixxing dicttoxml.
John Rouillard <rouilj@ieee.org>
parents:
5984
diff
changeset
|
2130 from roundup.dicttoxml import dicttoxml |
|
f1191a470598
Fix test to account for mixxing dicttoxml.
John Rouillard <rouilj@ieee.org>
parents:
5984
diff
changeset
|
2131 includexml = ', application/xml' |
|
f1191a470598
Fix test to account for mixxing dicttoxml.
John Rouillard <rouilj@ieee.org>
parents:
5984
diff
changeset
|
2132 except ImportError: |
|
f1191a470598
Fix test to account for mixxing dicttoxml.
John Rouillard <rouilj@ieee.org>
parents:
5984
diff
changeset
|
2133 includexml = '' |
|
f1191a470598
Fix test to account for mixxing dicttoxml.
John Rouillard <rouilj@ieee.org>
parents:
5984
diff
changeset
|
2134 |
|
5984
25a813415d59
issue2551069 - when unsupported type is found report type
John Rouillard <rouilj@ieee.org>
parents:
5937
diff
changeset
|
2135 response="Requested content type 'jon' is not available.\n" \ |
|
5985
f1191a470598
Fix test to account for mixxing dicttoxml.
John Rouillard <rouilj@ieee.org>
parents:
5984
diff
changeset
|
2136 "Acceptable types: */*, application/json%s\n"%includexml |
|
5987
ea3485c67f94
Sort accept keys to make p2 and p3 ordering the same
John Rouillard <rouilj@ieee.org>
parents:
5986
diff
changeset
|
2137 self.assertEqual(b2s(results), response) |
|
5984
25a813415d59
issue2551069 - when unsupported type is found report type
John Rouillard <rouilj@ieee.org>
parents:
5937
diff
changeset
|
2138 |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2139 # TEST #9 |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2140 # GET: test that version can be set with accept: |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2141 # ... ; version=z |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2142 # or |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2143 # application/vnd.x.y-vz+json |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2144 # or |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2145 # @apiver |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2146 # simulate: /rest/data/issue |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2147 form = cgi.FieldStorage() |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2148 form.list = [ |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2149 cgi.MiniFieldStorage('@apiver', 'L'), |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2150 ] |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2151 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2152 self.server.client.env.update({'REQUEST_METHOD': 'GET'}) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2153 |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2154 headers={"accept": "application/json; notversion=z" } |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2155 self.headers=headers |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2156 self.server.client.request.headers.get=self.get_header |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2157 results = self.server.dispatch('GET', |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2158 "/rest/data/issue/1", form) |
|
5987
ea3485c67f94
Sort accept keys to make p2 and p3 ordering the same
John Rouillard <rouilj@ieee.org>
parents:
5986
diff
changeset
|
2159 print("9a: " + b2s(results)) |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2160 json_dict = json.loads(b2s(results)) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2161 self.assertEqual(json_dict['error']['status'], 400) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2162 self.assertEqual(json_dict['error']['msg'], |
| 6513 | 2163 "Unrecognized api version: L. See /rest without " |
| 2164 "specifying api version for supported versions.") | |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2165 |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2166 headers={"accept": "application/json; version=z" } |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2167 self.headers=headers |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2168 self.server.client.request.headers.get=self.get_header |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2169 results = self.server.dispatch('GET', |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2170 "/rest/data/issue/1", form) |
|
5987
ea3485c67f94
Sort accept keys to make p2 and p3 ordering the same
John Rouillard <rouilj@ieee.org>
parents:
5986
diff
changeset
|
2171 print("9b: " + b2s(results)) |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2172 json_dict = json.loads(b2s(results)) |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2173 self.assertEqual(json_dict['error']['status'], 400) |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2174 self.assertEqual(json_dict['error']['msg'], |
| 6513 | 2175 "Unrecognized api version: z. See /rest without " |
| 2176 "specifying api version for supported versions.") | |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2177 |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2178 headers={"accept": "application/vnd.roundup.test-vz+json" } |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2179 self.headers=headers |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2180 self.server.client.request.headers.get=self.get_header |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2181 results = self.server.dispatch('GET', |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2182 "/rest/data/issue/1", self.empty_form) |
|
5987
ea3485c67f94
Sort accept keys to make p2 and p3 ordering the same
John Rouillard <rouilj@ieee.org>
parents:
5986
diff
changeset
|
2183 print("9c:" + b2s(results)) |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2184 self.assertEqual(self.server.client.response_code, 400) |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2185 json_dict = json.loads(b2s(results)) |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2186 self.assertEqual(json_dict['error']['status'], 400) |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2187 self.assertEqual(json_dict['error']['msg'], |
| 6513 | 2188 "Unrecognized api version: z. See /rest without " |
| 2189 "specifying api version for supported versions.") | |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2190 |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2191 # verify that version priority is correct; should be version=... |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2192 headers={"accept": "application/vnd.roundup.test-vz+json; version=a" |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2193 } |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2194 self.headers=headers |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2195 self.server.client.request.headers.get=self.get_header |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2196 results = self.server.dispatch('GET', |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2197 "/rest/data/issue/1", self.empty_form) |
|
5987
ea3485c67f94
Sort accept keys to make p2 and p3 ordering the same
John Rouillard <rouilj@ieee.org>
parents:
5986
diff
changeset
|
2198 print("9d: " + b2s(results)) |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2199 self.assertEqual(self.server.client.response_code, 400) |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2200 json_dict = json.loads(b2s(results)) |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2201 self.assertEqual(json_dict['error']['status'], 400) |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2202 self.assertEqual(json_dict['error']['msg'], |
| 6513 | 2203 "Unrecognized api version: a. See /rest without " |
| 2204 "specifying api version for supported versions.") | |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
2205 |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2206 # TEST #10 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2207 # check /rest and /rest/summary and /rest/notthere |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2208 expected_rest = { |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2209 "data": { |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2210 "supported_versions": [ |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2211 1 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2212 ], |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2213 "default_version": 1, |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2214 "links": [ |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2215 { |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2216 "rel": "self", |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2217 "uri": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest" |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2218 }, |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2219 { |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2220 "rel": "data", |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2221 "uri": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data" |
|
6525
c505c774a94d
Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents:
6513
diff
changeset
|
2222 }, |
|
c505c774a94d
Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents:
6513
diff
changeset
|
2223 { |
|
c505c774a94d
Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents:
6513
diff
changeset
|
2224 "rel": "summary", |
|
c505c774a94d
Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents:
6513
diff
changeset
|
2225 "uri": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/summary" |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2226 } |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2227 ] |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2228 } |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2229 } |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2230 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2231 self.headers={} |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2232 results = self.server.dispatch('GET', |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2233 "/rest", self.empty_form) |
|
5987
ea3485c67f94
Sort accept keys to make p2 and p3 ordering the same
John Rouillard <rouilj@ieee.org>
parents:
5986
diff
changeset
|
2234 print("10a: " + b2s(results)) |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2235 self.assertEqual(self.server.client.response_code, 200) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2236 results_dict = json.loads(b2s(results)) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2237 self.assertEqual(results_dict, expected_rest) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2238 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2239 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2240 results = self.server.dispatch('GET', |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2241 "/rest/", self.empty_form) |
|
5987
ea3485c67f94
Sort accept keys to make p2 and p3 ordering the same
John Rouillard <rouilj@ieee.org>
parents:
5986
diff
changeset
|
2242 print("10b: " + b2s(results)) |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2243 self.assertEqual(self.server.client.response_code, 200) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2244 results_dict = json.loads(b2s(results)) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2245 self.assertEqual(results_dict, expected_rest) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2246 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2247 results = self.server.dispatch('GET', |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2248 "/rest/summary", self.empty_form) |
|
5987
ea3485c67f94
Sort accept keys to make p2 and p3 ordering the same
John Rouillard <rouilj@ieee.org>
parents:
5986
diff
changeset
|
2249 print("10c: " + b2s(results)) |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2250 self.assertEqual(self.server.client.response_code, 200) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2251 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2252 results = self.server.dispatch('GET', |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2253 "/rest/summary/", self.empty_form) |
|
5987
ea3485c67f94
Sort accept keys to make p2 and p3 ordering the same
John Rouillard <rouilj@ieee.org>
parents:
5986
diff
changeset
|
2254 print("10d: " + b2s(results)) |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2255 self.assertEqual(self.server.client.response_code, 200) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2256 |
| 5746 | 2257 expected_data = { |
| 2258 "data": { | |
| 2259 "issue": { | |
| 2260 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue" | |
| 2261 }, | |
| 2262 "priority": { | |
| 2263 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/priority" | |
| 2264 }, | |
| 2265 "user": { | |
| 2266 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user" | |
| 2267 }, | |
| 2268 "query": { | |
| 2269 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/query" | |
| 2270 }, | |
| 2271 "status": { | |
| 2272 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/status" | |
| 2273 }, | |
| 2274 "keyword": { | |
| 2275 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/keyword" | |
| 2276 }, | |
| 2277 "msg": { | |
| 2278 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/msg" | |
| 2279 }, | |
| 2280 "file": { | |
| 2281 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/file" | |
| 2282 } | |
| 2283 } | |
| 2284 } | |
| 2285 | |
| 2286 results = self.server.dispatch('GET', | |
| 2287 "/rest/data", self.empty_form) | |
|
5987
ea3485c67f94
Sort accept keys to make p2 and p3 ordering the same
John Rouillard <rouilj@ieee.org>
parents:
5986
diff
changeset
|
2288 print("10e: " + b2s(results)) |
| 5746 | 2289 self.assertEqual(self.server.client.response_code, 200) |
| 2290 results_dict = json.loads(b2s(results)) | |
| 2291 self.assertEqual(results_dict, expected_data) | |
| 2292 | |
| 2293 results = self.server.dispatch('GET', | |
| 2294 "/rest/data/", self.empty_form) | |
|
5987
ea3485c67f94
Sort accept keys to make p2 and p3 ordering the same
John Rouillard <rouilj@ieee.org>
parents:
5986
diff
changeset
|
2295 print("10f: " + b2s(results)) |
| 5746 | 2296 self.assertEqual(self.server.client.response_code, 200) |
| 2297 results_dict = json.loads(b2s(results)) | |
| 2298 self.assertEqual(results_dict, expected_data) | |
| 2299 | |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2300 results = self.server.dispatch('GET', |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2301 "/rest/notthere", self.empty_form) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2302 self.assertEqual(self.server.client.response_code, 404) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2303 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2304 results = self.server.dispatch('GET', |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2305 "/rest/notthere/", self.empty_form) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2306 self.assertEqual(self.server.client.response_code, 404) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
2307 |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2308 del(self.headers) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2309 |
|
5744
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2310 def testAcceptHeaderParsing(self): |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2311 self.server.client.env['REQUEST_METHOD'] = 'GET' |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2312 |
|
5744
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2313 # TEST #1 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2314 # json highest priority |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2315 self.server.client.request.headers.get=self.get_header |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2316 headers={"accept": "application/json; version=1," |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2317 "application/xml; q=0.5; version=2," |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2318 "text/plain; q=0.75; version=2" |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2319 } |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2320 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2321 results = self.server.dispatch('GET', |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2322 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2323 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2324 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2325 self.assertEqual(self.server.client.response_code, 200) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2326 self.assertEqual(self.server.client.additional_headers['Content-Type'], |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2327 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2328 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2329 # TEST #2 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2330 # text highest priority |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2331 headers={"accept": "application/json; q=0.5; version=1," |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2332 "application/xml; q=0.25; version=2," |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2333 "text/plain; q=1.0; version=3" |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2334 } |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2335 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2336 results = self.server.dispatch('GET', |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2337 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2338 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2339 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2340 self.assertEqual(self.server.client.response_code, 200) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2341 self.assertEqual(self.server.client.additional_headers['Content-Type'], |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2342 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2343 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2344 # TEST #3 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2345 # no acceptable type |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2346 headers={"accept": "text/plain; q=1.0; version=2" |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2347 } |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2348 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2349 results = self.server.dispatch('GET', |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2350 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2351 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2352 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2353 self.assertEqual(self.server.client.response_code, 406) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2354 self.assertEqual(self.server.client.additional_headers['Content-Type'], |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2355 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2356 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2357 # TEST #4 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2358 # no accept header, should use default json |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2359 headers={} |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2360 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2361 results = self.server.dispatch('GET', |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2362 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2363 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2364 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2365 self.assertEqual(self.server.client.response_code, 200) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2366 self.assertEqual(self.server.client.additional_headers['Content-Type'], |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2367 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2368 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2369 # TEST #5 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2370 # wildcard accept header, should use default json |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2371 headers={ "accept": "*/*"} |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2372 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2373 results = self.server.dispatch('GET', |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2374 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2375 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2376 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2377 self.assertEqual(self.server.client.response_code, 200) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2378 self.assertEqual(self.server.client.additional_headers['Content-Type'], |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2379 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2380 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2381 # TEST #6 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2382 # invalid q factor if not ignored/demoted |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2383 # application/json is selected with invalid version |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2384 # and errors. |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2385 # this ends up choosing */* which triggers json. |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2386 self.server.client.request.headers.get=self.get_header |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2387 headers={"accept": "application/json; q=1.5; version=99," |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2388 "*/*; q=0.9; version=1," |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2389 "text/plain; q=3.75; version=2" |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2390 } |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2391 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2392 results = self.server.dispatch('GET', |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2393 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2394 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2395 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2396 self.assertEqual(self.server.client.response_code, 200) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2397 self.assertEqual(self.server.client.additional_headers['Content-Type'], |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2398 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2399 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2400 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2401 ''' |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2402 # only works if dicttoxml.py is installed. |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2403 # not installed for testing |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2404 # TEST #7 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2405 # xml wins |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2406 headers={"accept": "application/json; q=0.5; version=2," |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2407 "application/xml; q=0.75; version=1," |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2408 "text/plain; q=1.0; version=2" |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2409 } |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2410 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2411 results = self.server.dispatch('GET', |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2412 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2413 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2414 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2415 self.assertEqual(self.server.client.response_code, 200) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2416 self.assertEqual(self.server.client.additional_headers['Content-Type'], |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2417 "application/xml") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2418 ''' |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2419 |
|
6316
323661f7c89c
Test handling of invalid API version using Accept header.
John Rouillard <rouilj@ieee.org>
parents:
6314
diff
changeset
|
2420 # TEST #8 |
|
323661f7c89c
Test handling of invalid API version using Accept header.
John Rouillard <rouilj@ieee.org>
parents:
6314
diff
changeset
|
2421 # invalid api version |
|
323661f7c89c
Test handling of invalid API version using Accept header.
John Rouillard <rouilj@ieee.org>
parents:
6314
diff
changeset
|
2422 # application/json is selected with invalid version |
|
323661f7c89c
Test handling of invalid API version using Accept header.
John Rouillard <rouilj@ieee.org>
parents:
6314
diff
changeset
|
2423 self.server.client.request.headers.get=self.get_header |
|
323661f7c89c
Test handling of invalid API version using Accept header.
John Rouillard <rouilj@ieee.org>
parents:
6314
diff
changeset
|
2424 headers={"accept": "application/json; version=99" |
|
323661f7c89c
Test handling of invalid API version using Accept header.
John Rouillard <rouilj@ieee.org>
parents:
6314
diff
changeset
|
2425 } |
|
323661f7c89c
Test handling of invalid API version using Accept header.
John Rouillard <rouilj@ieee.org>
parents:
6314
diff
changeset
|
2426 self.headers=headers |
|
6509
1fc765ef6379
Fix 204 responses, hangs and crashes with REST.
John Rouillard <rouilj@ieee.org>
parents:
6366
diff
changeset
|
2427 results = self.server.dispatch('GET', |
|
1fc765ef6379
Fix 204 responses, hangs and crashes with REST.
John Rouillard <rouilj@ieee.org>
parents:
6366
diff
changeset
|
2428 "/rest/data/status/1", |
|
1fc765ef6379
Fix 204 responses, hangs and crashes with REST.
John Rouillard <rouilj@ieee.org>
parents:
6366
diff
changeset
|
2429 self.empty_form) |
|
6316
323661f7c89c
Test handling of invalid API version using Accept header.
John Rouillard <rouilj@ieee.org>
parents:
6314
diff
changeset
|
2430 print(results) |
|
6509
1fc765ef6379
Fix 204 responses, hangs and crashes with REST.
John Rouillard <rouilj@ieee.org>
parents:
6366
diff
changeset
|
2431 json_dict = json.loads(b2s(results)) |
|
1fc765ef6379
Fix 204 responses, hangs and crashes with REST.
John Rouillard <rouilj@ieee.org>
parents:
6366
diff
changeset
|
2432 self.assertEqual(self.server.client.response_code, 400) |
|
1fc765ef6379
Fix 204 responses, hangs and crashes with REST.
John Rouillard <rouilj@ieee.org>
parents:
6366
diff
changeset
|
2433 self.assertEqual(self.server.client.additional_headers['Content-Type'], |
|
1fc765ef6379
Fix 204 responses, hangs and crashes with REST.
John Rouillard <rouilj@ieee.org>
parents:
6366
diff
changeset
|
2434 "application/json") |
|
1fc765ef6379
Fix 204 responses, hangs and crashes with REST.
John Rouillard <rouilj@ieee.org>
parents:
6366
diff
changeset
|
2435 self.assertEqual(json_dict['error']['msg'], |
| 6512 | 2436 "Unrecognized api version: 99. See /rest " |
| 2437 "without specifying api version for " | |
| 2438 "supported versions.") | |
|
6316
323661f7c89c
Test handling of invalid API version using Accept header.
John Rouillard <rouilj@ieee.org>
parents:
6314
diff
changeset
|
2439 |
|
5743
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2440 def testMethodOverride(self): |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2441 # TEST #1 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2442 # Use GET, PUT, PATCH to tunnel DELETE expect error |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2443 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2444 body=b'{ "order": 5 }' |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2445 env = { "CONTENT_TYPE": "application/json", |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2446 "CONTENT_LENGTH": len(body), |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2447 "REQUEST_METHOD": "POST" |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2448 } |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2449 body_file=BytesIO(body) # FieldStorage needs a file |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2450 self.server.client.request.headers.get=self.get_header |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2451 for method in ( "GET", "PUT", "PATCH" ): |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2452 headers={"accept": "application/json; version=1", |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2453 "content-type": env['CONTENT_TYPE'], |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2454 "content-length": len(body), |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2455 "x-http-method-override": "DElETE", |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2456 } |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2457 self.headers=headers |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2458 form = client.BinaryFieldStorage(body_file, |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2459 headers=headers, |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2460 environ=env) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2461 self.db.setCurrentUser('admin') # must be admin to create status |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2462 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2463 self.server.client.env.update({'REQUEST_METHOD': method}) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2464 |
|
5743
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2465 results = self.server.dispatch(method, |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2466 "/rest/data/status", |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2467 form) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2468 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2469 self.assertEqual(self.server.client.response_code, 400) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2470 json_dict = json.loads(b2s(results)) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2471 status=json_dict['error']['status'] |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2472 msg=json_dict['error']['msg'] |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2473 self.assertEqual(status, 400) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2474 self.assertEqual(msg, "X-HTTP-Method-Override: DElETE must be " |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2475 "used with POST method not %s."%method) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2476 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2477 # TEST #2 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2478 # DELETE: delete issue 1 via post tunnel |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2479 self.assertFalse(self.db.status.is_retired("1")) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2480 etag = calculate_etag(self.db.status.getnode("1"), |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2481 self.db.config['WEB_SECRET_KEY']) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2482 etagb = etag.strip ('"') |
|
5744
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
2483 headers={"accept": "application/json; q=1.0, application/xml; q=0.75", |
|
5743
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2484 "if-match": '"%s"'%etagb, |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2485 "content-length": 0, |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2486 "x-http-method-override": "DElETE" |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2487 } |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2488 self.headers=headers |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2489 body_file=BytesIO(b'') # FieldStorage needs a file |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2490 form = client.BinaryFieldStorage(body_file, |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2491 headers=headers, |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2492 environ=env) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2493 self.server.client.request.headers.get=self.get_header |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2494 self.db.setCurrentUser('admin') # must be admin to delete issue |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2495 self.server.client.env.update({'REQUEST_METHOD': 'POST'}) |
|
5743
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2496 results = self.server.dispatch('POST', |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2497 "/rest/data/status/1", |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2498 form) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2499 print(results) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2500 self.assertEqual(self.server.client.response_code, 200) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2501 json_dict = json.loads(b2s(results)) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2502 status=json_dict['data']['status'] |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2503 self.assertEqual(status, 'ok') |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2504 self.assertTrue(self.db.status.is_retired("1")) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2505 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
2506 |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2507 def testPostPOE(self): |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2508 ''' test post once exactly: get POE url, create issue |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2509 using POE url. Use dispatch entry point. |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2510 ''' |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2511 import time |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2512 # setup environment |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2513 etag = "not needed" |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2514 empty_body=b'' |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2515 env = { "CONTENT_TYPE": "application/json", |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2516 "CONTENT_LENGTH": len(empty_body), |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2517 "REQUEST_METHOD": "POST" |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2518 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2519 self.server.client.env.update(env) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2520 |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2521 headers={"accept": "application/json", |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2522 "content-type": env['CONTENT_TYPE'], |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2523 "content-length": len(empty_body) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2524 } |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2525 self.headers=headers |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2526 # use empty_body to test code path for missing/empty json |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2527 body_file=BytesIO(empty_body) # FieldStorage needs a file |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2528 form = client.BinaryFieldStorage(body_file, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2529 headers=headers, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2530 environ=env) |
|
5710
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2531 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2532 ## Obtain the POE url. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2533 self.server.client.request.headers.get=self.get_header |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2534 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2535 "/rest/data/issue/@poe", |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2536 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2537 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2538 self.assertEqual(self.server.client.response_code, 200) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2539 json_dict = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2540 url=json_dict['data']['link'] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2541 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2542 # strip tracker web prefix leaving leading /. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2543 url = url[len(self.db.config['TRACKER_WEB'])-1:] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2544 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2545 ## create an issue using poe url. |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2546 body=b'{ "title": "foo bar", "priority": "critical" }' |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2547 env = { "CONTENT_TYPE": "application/json", |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2548 "CONTENT_LENGTH": len(body), |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2549 "REQUEST_METHOD": "POST" |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2550 } |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2551 self.server.client.env.update(env) |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2552 headers={"accept": "application/json", |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2553 "content-type": env['CONTENT_TYPE'], |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2554 "content-length": len(body) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2555 } |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2556 self.headers=headers |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2557 body_file=BytesIO(body) # FieldStorage needs a file |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2558 form = client.BinaryFieldStorage(body_file, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2559 headers=headers, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
2560 environ=env) |
|
5710
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2561 self.server.client.request.headers.get=self.get_header |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2562 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2563 url, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2564 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2565 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2566 self.assertEqual(self.server.client.response_code, 201) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2567 json_dict = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2568 issue_id=json_dict['data']['id'] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2569 results = self.server.get_element('issue', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2570 str(issue_id), # must be a string not unicode |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2571 self.empty_form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2572 self.assertEqual(self.dummy_client.response_code, 200) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2573 self.assertEqual(results['data']['attributes']['title'], |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2574 'foo bar') |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2575 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2576 ## Reuse POE url. It will fail. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2577 self.server.client.request.headers.get=self.get_header |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2578 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2579 url, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2580 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2581 # get the last component stripping the trailing / |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2582 poe=url[url.rindex('/')+1:] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2583 self.assertEqual(self.server.client.response_code, 400) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2584 results = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2585 self.assertEqual(results['error']['status'], 400) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2586 self.assertEqual(results['error']['msg'], |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2587 "POE token \'%s\' not valid."%poe) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2588 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2589 ## Try using GET on POE url. Should fail with method not |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2590 ## allowed (405) |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2591 self.server.client.env.update({'REQUEST_METHOD': 'GET'}) |
|
5710
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2592 self.server.client.request.headers.get=self.get_header |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2593 results = self.server.dispatch('GET', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2594 "/rest/data/issue/@poe", |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2595 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2596 self.assertEqual(self.server.client.response_code, 405) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2597 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2598 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2599 ## Try creating generic POE url. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2600 body_poe=b'{"generic": "null", "lifetime": "100" }' |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2601 body_file=BytesIO(body_poe) # FieldStorage needs a file |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2602 form = client.BinaryFieldStorage(body_file, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2603 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2604 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2605 self.server.client.request.headers.get=self.get_header |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
2606 self.server.client.env.update({'REQUEST_METHOD': 'POST'}) |
|
5710
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2607 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2608 "/rest/data/issue/@poe", |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2609 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2610 json_dict = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2611 url=json_dict['data']['link'] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2612 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2613 # strip tracker web prefix leaving leading /. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2614 url = url[len(self.db.config['TRACKER_WEB'])-1:] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2615 url = url.replace('/issue/', '/keyword/') |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2616 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2617 body_keyword=b'{"name": "keyword"}' |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2618 body_file=BytesIO(body_keyword) # FieldStorage needs a file |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2619 form = client.BinaryFieldStorage(body_file, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2620 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2621 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2622 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2623 url, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2624 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2625 self.assertEqual(self.server.client.response_code, 201) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2626 json_dict = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2627 url=json_dict['data']['link'] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2628 id=json_dict['data']['id'] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2629 self.assertEqual(id, "1") |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2630 self.assertEqual(url, "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/keyword/1") |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2631 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2632 ## Create issue POE url and try to use for keyword. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2633 ## This should fail. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2634 body_poe=b'{"lifetime": "100" }' |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2635 body_file=BytesIO(body_poe) # FieldStorage needs a file |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2636 form = client.BinaryFieldStorage(body_file, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2637 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2638 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2639 self.server.client.request.headers.get=self.get_header |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2640 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2641 "/rest/data/issue/@poe", |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2642 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2643 json_dict = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2644 url=json_dict['data']['link'] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2645 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2646 # strip tracker web prefix leaving leading /. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2647 url = url[len(self.db.config['TRACKER_WEB'])-1:] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2648 url = url.replace('/issue/', '/keyword/') |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2649 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2650 body_keyword=b'{"name": "keyword"}' |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2651 body_file=BytesIO(body_keyword) # FieldStorage needs a file |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2652 form = client.BinaryFieldStorage(body_file, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2653 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2654 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2655 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2656 url, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2657 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2658 poe=url[url.rindex('/')+1:] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2659 self.assertEqual(self.server.client.response_code, 400) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2660 json_dict = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2661 stat=json_dict['error']['status'] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2662 msg=json_dict['error']['msg'] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2663 self.assertEqual(stat, 400) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2664 self.assertEqual(msg, "POE token '%s' not valid for keyword, was generated for class issue"%poe) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2665 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2666 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2667 ## Create POE with 10 minute lifetime and verify |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2668 ## expires is within 10 minutes. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2669 body_poe=b'{"lifetime": "30" }' |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2670 body_file=BytesIO(body_poe) # FieldStorage needs a file |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2671 form = client.BinaryFieldStorage(body_file, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2672 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2673 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2674 self.server.client.request.headers.get=self.get_header |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2675 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2676 "/rest/data/issue/@poe", |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2677 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2678 json_dict = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2679 expires=int(json_dict['data']['expires']) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2680 # allow up to 3 seconds between time stamp creation |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2681 # done under dispatch and this point. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2682 expected=int(time.time() + 30) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2683 print("expected=%d, expires=%d"%(expected,expires)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2684 self.assertTrue((expected - expires) < 3 and (expected - expires) >= 0) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2685 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2686 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2687 ## Use a token created above as joe by a different user. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2688 self.db.setCurrentUser('admin') |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2689 url=json_dict['data']['link'] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2690 # strip tracker web prefix leaving leading /. |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2691 url = url[len(self.db.config['TRACKER_WEB'])-1:] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2692 body_file=BytesIO(body_keyword) # FieldStorage needs a file |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2693 form = client.BinaryFieldStorage(body_file, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2694 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2695 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2696 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2697 url, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2698 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2699 print(results) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2700 self.assertEqual(self.server.client.response_code, 400) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2701 json_dict = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2702 # get the last component stripping the trailing / |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2703 poe=url[url.rindex('/')+1:] |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2704 self.assertEqual(json_dict['error']['msg'], |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2705 "POE token '%s' not valid."%poe) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2706 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2707 ## Create POE with bogus lifetime |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2708 body_poe=b'{"lifetime": "10.2" }' |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2709 body_file=BytesIO(body_poe) # FieldStorage needs a file |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2710 form = client.BinaryFieldStorage(body_file, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2711 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2712 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2713 self.server.client.request.headers.get=self.get_header |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2714 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2715 "/rest/data/issue/@poe", |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2716 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2717 self.assertEqual(self.server.client.response_code, 400) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2718 print(results) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2719 json_dict = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2720 self.assertEqual(json_dict['error']['msg'], |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2721 "Value \'lifetime\' must be an integer specify " |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2722 "lifetime in seconds. Got 10.2.") |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2723 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2724 ## Create POE with lifetime > 1 hour |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2725 body_poe=b'{"lifetime": "3700" }' |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2726 body_file=BytesIO(body_poe) # FieldStorage needs a file |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2727 form = client.BinaryFieldStorage(body_file, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2728 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2729 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2730 self.server.client.request.headers.get=self.get_header |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2731 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2732 "/rest/data/issue/@poe", |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2733 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2734 self.assertEqual(self.server.client.response_code, 400) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2735 print(results) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2736 json_dict = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2737 self.assertEqual(json_dict['error']['msg'], |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2738 "Value 'lifetime' must be between 1 second and 1 " |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2739 "hour (3600 seconds). Got 3700.") |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2740 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2741 ## Create POE with lifetime < 1 second |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2742 body_poe=b'{"lifetime": "-1" }' |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2743 body_file=BytesIO(body_poe) # FieldStorage needs a file |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2744 form = client.BinaryFieldStorage(body_file, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2745 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2746 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2747 self.server.client.request.headers.get=self.get_header |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2748 results = self.server.dispatch('POST', |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2749 "/rest/data/issue/@poe", |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2750 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2751 self.assertEqual(self.server.client.response_code, 400) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2752 print(results) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2753 json_dict = json.loads(b2s(results)) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2754 self.assertEqual(json_dict['error']['msg'], |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2755 "Value 'lifetime' must be between 1 second and 1 " |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2756 "hour (3600 seconds). Got -1.") |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2757 del(self.headers) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2758 |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2759 def testPutElement(self): |
| 5583 | 2760 """ |
| 2761 Change joe's 'realname' | |
| 2762 Check if we can't change admin's detail | |
| 2763 """ | |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2764 # fail to change Joe's realname via attribute uri |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2765 # no etag |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2766 form = cgi.FieldStorage() |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2767 form.list = [ |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2768 cgi.MiniFieldStorage('data', 'Joe Doe Doe') |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2769 ] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2770 results = self.server.put_attribute( |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2771 'user', self.joeid, 'realname', form |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2772 ) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2773 self.assertEqual(self.dummy_client.response_code, 412) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2774 results = self.server.get_attribute( |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2775 'user', self.joeid, 'realname', self.empty_form |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2776 ) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2777 self.assertEqual(self.dummy_client.response_code, 200) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2778 self.assertEqual(results['data']['data'], 'Joe Random') |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2779 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2780 # change Joe's realname via attribute uri - etag in header |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2781 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2782 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2783 self.db.config['WEB_SECRET_KEY']) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2784 form.list = [ |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2785 cgi.MiniFieldStorage('data', 'Joe Doe Doe'), |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2786 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2787 |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
2788 self.headers = {'if-match': etag } # use etag in header |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2789 results = self.server.put_attribute( |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2790 'user', self.joeid, 'realname', form |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2791 ) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2792 self.assertEqual(self.dummy_client.response_code, 200) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2793 results = self.server.get_attribute( |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
2794 'user', self.joeid, 'realname', self.empty_form |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2795 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2796 self.assertEqual(self.dummy_client.response_code, 200) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2797 self.assertEqual(results['data']['data'], 'Joe Doe Doe') |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2798 del(self.headers) |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2799 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2800 # Reset joe's 'realname'. etag in body |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2801 # Also try to set protected items. The protected items should |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2802 # be ignored on put_element to make it easy to get the item |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2803 # with all fields, change one field and put the result without |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2804 # having to filter out protected items. |
| 5583 | 2805 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2806 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2807 self.db.config['WEB_SECRET_KEY']) |
| 5583 | 2808 form.list = [ |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2809 cgi.MiniFieldStorage('creator', '3'), |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2810 cgi.MiniFieldStorage('realname', 'Joe Doe'), |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2811 cgi.MiniFieldStorage('@etag', etag) |
| 5583 | 2812 ] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2813 results = self.server.put_element('user', self.joeid, form) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2814 self.assertEqual(self.dummy_client.response_code, 200) |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
2815 results = self.server.get_element('user', self.joeid, self.empty_form) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2816 self.assertEqual(self.dummy_client.response_code, 200) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2817 self.assertEqual(results['data']['attributes']['realname'], 'Joe Doe') |
| 5583 | 2818 |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2819 # We are joe, so check we can't change admin's details |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2820 results = self.server.put_element('user', '1', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2821 self.assertEqual(self.dummy_client.response_code, 403) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2822 self.assertEqual(results['error']['status'], 403) |
| 5583 | 2823 |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2824 # Try to reset joe's 'realname' and add a broken prop. |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2825 # This should result in no change to the name and |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2826 # a 400 UsageError stating prop does not exist. |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2827 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2828 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2829 self.db.config['WEB_SECRET_KEY']) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2830 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2831 cgi.MiniFieldStorage('JustKidding', '3'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2832 cgi.MiniFieldStorage('realname', 'Joe Doe'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2833 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2834 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2835 results = self.server.put_element('user', self.joeid, form) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2836 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2837 'msg': UsageError('Property JustKidding not ' |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2838 'found in class user')}} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2839 self.assertEqual(results['error']['status'], |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2840 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2841 self.assertEqual(type(results['error']['msg']), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2842 type(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2843 self.assertEqual(self.dummy_client.response_code, 400) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2844 results = self.server.get_element('user', self.joeid, self.empty_form) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2845 self.assertEqual(self.dummy_client.response_code, 200) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2846 self.assertEqual(results['data']['attributes']['realname'], 'Joe Doe') |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2847 |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2848 def testPutAttribute(self): |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2849 # put protected property |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2850 # make sure we don't have permission issues |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2851 self.db.setCurrentUser('admin') |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2852 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2853 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2854 self.db.config['WEB_SECRET_KEY']) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2855 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2856 cgi.MiniFieldStorage('data', '3'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2857 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2858 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2859 results = self.server.put_attribute( |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2860 'user', self.joeid, 'creator', form |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2861 ) |
|
5707
f9a762678af6
Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents:
5706
diff
changeset
|
2862 expected= {'error': {'status': 405, 'msg': |
|
f9a762678af6
Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents:
5706
diff
changeset
|
2863 AttributeError('\'"creator", "actor", "creation" and ' |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2864 '"activity" are reserved\'')}} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2865 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2866 self.assertEqual(results['error']['status'], |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2867 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2868 self.assertEqual(type(results['error']['msg']), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2869 type(expected['error']['msg'])) |
|
5707
f9a762678af6
Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents:
5706
diff
changeset
|
2870 self.assertEqual(self.dummy_client.response_code, 405) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2871 |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2872 # put invalid property |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2873 # make sure we don't have permission issues |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2874 self.db.setCurrentUser('admin') |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2875 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2876 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2877 self.db.config['WEB_SECRET_KEY']) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2878 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2879 cgi.MiniFieldStorage('data', '3'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2880 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2881 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2882 results = self.server.put_attribute( |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2883 'user', self.joeid, 'youMustBeKiddingMe', form |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2884 ) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2885 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2886 'msg': UsageError("'youMustBeKiddingMe' " |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2887 "is not a property of user")}} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2888 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2889 self.assertEqual(results['error']['status'], |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2890 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2891 self.assertEqual(type(results['error']['msg']), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2892 type(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2893 self.assertEqual(self.dummy_client.response_code, 400) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2894 |
| 5583 | 2895 def testPost(self): |
| 2896 """ | |
| 2897 Post a new issue with title: foo | |
| 2898 Verify the information of the created issue | |
| 2899 """ | |
| 2900 form = cgi.FieldStorage() | |
| 2901 form.list = [ | |
| 2902 cgi.MiniFieldStorage('title', 'foo') | |
| 2903 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2904 results = self.server.post_collection('issue', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2905 self.assertEqual(self.dummy_client.response_code, 201) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2906 issueid = results['data']['id'] |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
2907 results = self.server.get_element('issue', issueid, self.empty_form) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2908 self.assertEqual(self.dummy_client.response_code, 200) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2909 self.assertEqual(results['data']['attributes']['title'], 'foo') |
| 5583 | 2910 self.assertEqual(self.db.issue.get(issueid, "tx_Source"), 'web') |
| 2911 | |
| 2912 def testPostFile(self): | |
| 2913 """ | |
| 2914 Post a new file with content: hello\r\nthere | |
| 2915 Verify the information of the created file | |
| 2916 """ | |
| 2917 form = cgi.FieldStorage() | |
| 2918 form.list = [ | |
| 2919 cgi.MiniFieldStorage('content', 'hello\r\nthere') | |
| 2920 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2921 results = self.server.post_collection('file', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2922 self.assertEqual(self.dummy_client.response_code, 201) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2923 fileid = results['data']['id'] |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
2924 results = self.server.get_element('file', fileid, self.empty_form) |
|
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
2925 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2926 self.assertEqual(self.dummy_client.response_code, 200) |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2927 self.assertEqual(results['attributes']['content'], |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2928 {'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/file1/'}) |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2929 |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2930 # File content is only shown with verbose=3 |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2931 form = cgi.FieldStorage() |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2932 form.list = [ |
|
6317
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
2933 cgi.MiniFieldStorage('@verbose', '3'), |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
2934 cgi.MiniFieldStorage('@protected', 'true') |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2935 ] |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2936 results = self.server.get_element('file', fileid, form) |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2937 results = results['data'] |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2938 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 2939 self.assertEqual(results['attributes']['content'], 'hello\r\nthere') |
|
6317
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
2940 self.assertIn('creator', results['attributes']) # added by @protected |
|
ea0becc9fdb9
Test delete of class and use of @protected.
John Rouillard <rouilj@ieee.org>
parents:
6316
diff
changeset
|
2941 self.assertEqual(results['attributes']['creator']['username'], "joe") |
| 5583 | 2942 |
| 2943 def testAuthDeniedPut(self): | |
| 2944 """ | |
| 2945 Test unauthorized PUT request | |
| 2946 """ | |
| 2947 # Wrong permissions (caught by roundup security module). | |
| 2948 form = cgi.FieldStorage() | |
| 2949 form.list = [ | |
| 2950 cgi.MiniFieldStorage('realname', 'someone') | |
| 2951 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2952 results = self.server.put_element('user', '1', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2953 self.assertEqual(self.dummy_client.response_code, 403) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2954 self.assertEqual(results['error']['status'], 403) |
| 5583 | 2955 |
| 2956 def testAuthDeniedPost(self): | |
| 2957 """ | |
| 2958 Test unauthorized POST request | |
| 2959 """ | |
| 2960 form = cgi.FieldStorage() | |
| 2961 form.list = [ | |
| 2962 cgi.MiniFieldStorage('username', 'blah') | |
| 2963 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2964 results = self.server.post_collection('user', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2965 self.assertEqual(self.dummy_client.response_code, 403) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2966 self.assertEqual(results['error']['status'], 403) |
| 5583 | 2967 |
| 2968 def testAuthAllowedPut(self): | |
| 2969 """ | |
| 2970 Test authorized PUT request | |
| 2971 """ | |
| 2972 self.db.setCurrentUser('admin') | |
| 2973 form = cgi.FieldStorage() | |
| 2974 form.list = [ | |
| 2975 cgi.MiniFieldStorage('realname', 'someone') | |
| 2976 ] | |
| 2977 try: | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2978 self.server.put_element('user', '2', form) |
| 5602 | 2979 except Unauthorised as err: |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2980 self.fail('raised %s' % err) |
| 5583 | 2981 finally: |
| 2982 self.db.setCurrentUser('joe') | |
| 2983 | |
| 2984 def testAuthAllowedPost(self): | |
| 2985 """ | |
| 2986 Test authorized POST request | |
| 2987 """ | |
| 2988 self.db.setCurrentUser('admin') | |
| 2989 form = cgi.FieldStorage() | |
| 2990 form.list = [ | |
| 2991 cgi.MiniFieldStorage('username', 'blah') | |
| 2992 ] | |
| 2993 try: | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2994 self.server.post_collection('user', form) |
| 5602 | 2995 except Unauthorised as err: |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2996 self.fail('raised %s' % err) |
| 5583 | 2997 finally: |
| 2998 self.db.setCurrentUser('joe') | |
| 2999 | |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3000 def testDeleteAttributeUri(self): |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3001 """ |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3002 Test Delete an attribute |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3003 """ |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3004 self.maxDiff = 4000 |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3005 # create a new issue with userid 1 in the nosy list |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3006 issue_id = self.db.issue.create(title='foo', nosy=['1']) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3007 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3008 # No etag, so this should return 412 - Precondition Failed |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3009 # With no changes |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3010 results = self.server.delete_attribute( |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3011 'issue', issue_id, 'nosy', self.empty_form |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3012 ) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3013 self.assertEqual(self.dummy_client.response_code, 412) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3014 results = self.server.get_element('issue', issue_id, self.empty_form) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3015 results = results['data'] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3016 self.assertEqual(self.dummy_client.response_code, 200) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3017 self.assertEqual(len(results['attributes']['nosy']), 1) |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3018 self.assertListEqual(results['attributes']['nosy'], |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3019 [{'id': '1', 'link': self.url_pfx + 'user/1'}]) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3020 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3021 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3022 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3023 self.db.config['WEB_SECRET_KEY']) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3024 form.list.append(cgi.MiniFieldStorage('@etag', etag)) |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3025 # remove the title and nosy |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3026 results = self.server.delete_attribute( |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3027 'issue', issue_id, 'title', form |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3028 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3029 self.assertEqual(self.dummy_client.response_code, 200) |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3030 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3031 del(form.list[-1]) |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3032 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3033 self.db.config['WEB_SECRET_KEY']) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3034 form.list.append(cgi.MiniFieldStorage('@etag', etag)) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3035 results = self.server.delete_attribute( |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3036 'issue', issue_id, 'nosy', form |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3037 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3038 self.assertEqual(self.dummy_client.response_code, 200) |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3039 |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3040 # verify the result |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3041 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
3042 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3043 self.assertEqual(self.dummy_client.response_code, 200) |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3044 self.assertEqual(len(results['attributes']['nosy']), 0) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3045 self.assertListEqual(results['attributes']['nosy'], []) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3046 self.assertEqual(results['attributes']['title'], None) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
3047 |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3048 # delete protected property |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3049 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3050 self.db.config['WEB_SECRET_KEY']) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3051 form.list.append(cgi.MiniFieldStorage('@etag', etag)) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3052 results = self.server.delete_attribute( |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3053 'issue', issue_id, 'creator', form |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3054 ) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3055 expected= {'error': { |
|
5707
f9a762678af6
Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents:
5706
diff
changeset
|
3056 'status': 405, |
|
f9a762678af6
Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents:
5706
diff
changeset
|
3057 'msg': AttributeError("Attribute 'creator' can not be updated for class issue.") |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3058 }} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3059 |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3060 self.assertEqual(results['error']['status'], |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3061 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3062 self.assertEqual(type(results['error']['msg']), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3063 type(expected['error']['msg'])) |
|
5707
f9a762678af6
Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents:
5706
diff
changeset
|
3064 self.assertEqual(self.dummy_client.response_code, 405) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3065 |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3066 # delete required property |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3067 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3068 self.db.config['WEB_SECRET_KEY']) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3069 form.list.append(cgi.MiniFieldStorage('@etag', etag)) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3070 results = self.server.delete_attribute( |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3071 'issue', issue_id, 'requireme', form |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3072 ) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3073 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3074 'msg': UsageError("Attribute 'requireme' is " |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3075 "required by class issue and can not be deleted.")}} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3076 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3077 self.assertEqual(results['error']['status'], |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3078 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3079 self.assertEqual(type(results['error']['msg']), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3080 type(expected['error']['msg'])) |
|
5706
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3081 self.assertEqual(str(results['error']['msg']), |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3082 str(expected['error']['msg'])) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3083 self.assertEqual(self.dummy_client.response_code, 400) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3084 |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3085 # delete bogus property |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3086 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3087 self.db.config['WEB_SECRET_KEY']) |
|
5706
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3088 form.list.append(cgi.MiniFieldStorage('@etag', etag)) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3089 results = self.server.delete_attribute( |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3090 'issue', issue_id, 'nosuchprop', form |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3091 ) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3092 expected= {'error': {'status': 400, |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3093 'msg': UsageError("Attribute 'nosuchprop' not valid " |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3094 "for class issue.")}} |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3095 print(results) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3096 self.assertEqual(results['error']['status'], |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3097 expected['error']['status']) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3098 self.assertEqual(type(results['error']['msg']), |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3099 type(expected['error']['msg'])) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3100 self.assertEqual(str(results['error']['msg']), |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3101 str(expected['error']['msg'])) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3102 self.assertEqual(self.dummy_client.response_code, 400) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3103 |
| 5583 | 3104 def testPatchAdd(self): |
| 3105 """ | |
| 3106 Test Patch op 'Add' | |
| 3107 """ | |
| 3108 # create a new issue with userid 1 in the nosy list | |
| 3109 issue_id = self.db.issue.create(title='foo', nosy=['1']) | |
| 3110 | |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3111 # fail to add userid 2 to the nosy list |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3112 # no etag |
| 5583 | 3113 form = cgi.FieldStorage() |
| 3114 form.list = [ | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3115 cgi.MiniFieldStorage('@op', 'add'), |
| 5583 | 3116 cgi.MiniFieldStorage('nosy', '2') |
| 3117 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3118 results = self.server.patch_element('issue', issue_id, form) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3119 self.assertEqual(self.dummy_client.response_code, 412) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3120 |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3121 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3122 self.db.config['WEB_SECRET_KEY']) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3123 form = cgi.FieldStorage() |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3124 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3125 cgi.MiniFieldStorage('@op', 'add'), |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3126 cgi.MiniFieldStorage('nosy', '2'), |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3127 cgi.MiniFieldStorage('@etag', etag) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3128 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3129 results = self.server.patch_element('issue', issue_id, form) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3130 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 3131 |
| 3132 # verify the result | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3133 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
3134 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3135 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 3136 self.assertListEqual(results['attributes']['nosy'], ['1', '2']) |
| 3137 | |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3138 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3139 self.db.config['WEB_SECRET_KEY']) |
|
5706
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3140 form = cgi.FieldStorage() |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3141 form.list = [ |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3142 cgi.MiniFieldStorage('@op', 'add'), |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3143 cgi.MiniFieldStorage('data', '3'), |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3144 cgi.MiniFieldStorage('@etag', etag) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3145 ] |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3146 results = self.server.patch_attribute('issue', issue_id, 'nosy', form) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3147 self.assertEqual(self.dummy_client.response_code, 200) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3148 |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3149 # verify the result |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3150 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3151 results = results['data'] |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3152 self.assertEqual(self.dummy_client.response_code, 200) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3153 self.assertListEqual(results['attributes']['nosy'], ['1', '2', '3']) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3154 |
|
6350
6a69584d117e
Remove length checks. We check list content explicitly.
John Rouillard <rouilj@ieee.org>
parents:
6318
diff
changeset
|
3155 |
|
5747
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3156 # patch with no new_val/data |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3157 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3158 self.db.config['WEB_SECRET_KEY']) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3159 form = cgi.FieldStorage() |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3160 form.list = [ |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3161 cgi.MiniFieldStorage('@op', 'add'), |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3162 cgi.MiniFieldStorage('data', ''), |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3163 cgi.MiniFieldStorage('@etag', etag) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3164 ] |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3165 results = self.server.patch_attribute('issue', issue_id, 'nosy', form) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3166 self.assertEqual(self.dummy_client.response_code, 200) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3167 |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3168 # verify the result |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3169 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3170 results = results['data'] |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3171 self.assertEqual(self.dummy_client.response_code, 200) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3172 self.assertListEqual(results['attributes']['nosy'], ['1', '2', '3']) |
|
5706
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3173 |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3174 # patch invalid property |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3175 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3176 self.db.config['WEB_SECRET_KEY']) |
|
5706
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3177 form = cgi.FieldStorage() |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3178 form.list = [ |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3179 cgi.MiniFieldStorage('@op', 'add'), |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3180 cgi.MiniFieldStorage('data', '3'), |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3181 cgi.MiniFieldStorage('@etag', etag) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3182 ] |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3183 results = self.server.patch_attribute('issue', issue_id, 'notGoingToWork', form) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3184 self.assertEqual(self.dummy_client.response_code, 400) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3185 print(results) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3186 expected={'error': {'status': 400, |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3187 'msg': UsageError( |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3188 HyperdbValueError( |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3189 "'notGoingToWork' is not a property of issue",),)}} |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3190 self.assertEqual(results['error']['status'], |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3191 expected['error']['status']) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3192 self.assertEqual(type(results['error']['msg']), |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3193 type(expected['error']['msg'])) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3194 self.assertEqual(str(results['error']['msg']), |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3195 str(expected['error']['msg'])) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3196 |
| 5583 | 3197 def testPatchReplace(self): |
| 3198 """ | |
| 3199 Test Patch op 'Replace' | |
| 3200 """ | |
| 3201 # create a new issue with userid 1 in the nosy list and status = 1 | |
| 3202 issue_id = self.db.issue.create(title='foo', nosy=['1'], status='1') | |
| 3203 | |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3204 # fail to replace userid 2 to the nosy list and status = 3 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3205 # no etag. |
| 5583 | 3206 form = cgi.FieldStorage() |
| 3207 form.list = [ | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3208 cgi.MiniFieldStorage('@op', 'replace'), |
| 5583 | 3209 cgi.MiniFieldStorage('nosy', '2'), |
| 3210 cgi.MiniFieldStorage('status', '3') | |
| 3211 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3212 results = self.server.patch_element('issue', issue_id, form) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3213 self.assertEqual(self.dummy_client.response_code, 412) |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3214 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3215 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3216 self.assertEqual(self.dummy_client.response_code, 200) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3217 self.assertEqual(results['attributes']['status'], '1') |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3218 self.assertListEqual(results['attributes']['nosy'], ['1']) |
| 5583 | 3219 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3220 # replace userid 2 to the nosy list and status = 3 |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3221 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3222 self.db.config['WEB_SECRET_KEY']) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3223 form = cgi.FieldStorage() |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3224 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3225 cgi.MiniFieldStorage('@op', 'replace'), |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3226 cgi.MiniFieldStorage('nosy', '2'), |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3227 cgi.MiniFieldStorage('status', '3'), |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3228 cgi.MiniFieldStorage('@etag', etag) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3229 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3230 results = self.server.patch_element('issue', issue_id, form) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3231 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 3232 # verify the result |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3233 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
3234 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3235 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 3236 self.assertEqual(results['attributes']['status'], '3') |
| 3237 self.assertListEqual(results['attributes']['nosy'], ['2']) | |
| 3238 | |
|
5706
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3239 # replace status = 2 using status attribute |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3240 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3241 self.db.config['WEB_SECRET_KEY']) |
|
5706
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3242 form = cgi.FieldStorage() |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3243 form.list = [ |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3244 cgi.MiniFieldStorage('@op', 'replace'), |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3245 cgi.MiniFieldStorage('data', '2'), |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3246 cgi.MiniFieldStorage('@etag', etag) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3247 ] |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3248 results = self.server.patch_attribute('issue', issue_id, 'status', |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3249 form) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3250 self.assertEqual(self.dummy_client.response_code, 200) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3251 # verify the result |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3252 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3253 results = results['data'] |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3254 self.assertEqual(self.dummy_client.response_code, 200) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3255 self.assertEqual(results['attributes']['status'], '2') |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
3256 |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3257 # try to set a protected prop. It should fail. |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3258 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3259 self.db.config['WEB_SECRET_KEY']) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3260 form = cgi.FieldStorage() |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3261 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3262 cgi.MiniFieldStorage('@op', 'replace'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3263 cgi.MiniFieldStorage('creator', '2'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3264 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3265 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3266 results = self.server.patch_element('issue', issue_id, form) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3267 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3268 'msg': KeyError('"creator", "actor", "creation" and "activity" are reserved',)}} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3269 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3270 self.assertEqual(results['error']['status'], |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3271 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3272 self.assertEqual(type(results['error']['msg']), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3273 type(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3274 self.assertEqual(str(results['error']['msg']), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3275 str(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3276 self.assertEqual(self.dummy_client.response_code, 400) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3277 |
|
5708
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3278 # try to set a protected prop using patch_attribute. It should |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3279 # fail with a 405 bad/unsupported method. |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3280 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3281 self.db.config['WEB_SECRET_KEY']) |
|
5708
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3282 form = cgi.FieldStorage() |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3283 form.list = [ |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3284 cgi.MiniFieldStorage('@op', 'replace'), |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3285 cgi.MiniFieldStorage('data', '2'), |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3286 cgi.MiniFieldStorage('@etag', etag) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3287 ] |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3288 results = self.server.patch_attribute('issue', issue_id, 'creator', |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3289 form) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3290 expected= {'error': {'status': 405, |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3291 'msg': AttributeError("Attribute 'creator' can not be updated for class issue.",)}} |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3292 print(results) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3293 self.assertEqual(results['error']['status'], |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3294 expected['error']['status']) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3295 self.assertEqual(type(results['error']['msg']), |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3296 type(expected['error']['msg'])) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3297 self.assertEqual(str(results['error']['msg']), |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3298 str(expected['error']['msg'])) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3299 self.assertEqual(self.dummy_client.response_code, 405) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
3300 |
| 5583 | 3301 def testPatchRemoveAll(self): |
| 3302 """ | |
| 3303 Test Patch Action 'Remove' | |
| 3304 """ | |
|
5595
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3305 # create a new issue with userid 1 and 2 in the nosy list |
| 5583 | 3306 issue_id = self.db.issue.create(title='foo', nosy=['1', '2']) |
| 3307 | |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3308 # fail to remove the nosy list and the title |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3309 # no etag |
| 5583 | 3310 form = cgi.FieldStorage() |
| 3311 form.list = [ | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3312 cgi.MiniFieldStorage('@op', 'remove'), |
| 5583 | 3313 cgi.MiniFieldStorage('nosy', ''), |
| 3314 cgi.MiniFieldStorage('title', '') | |
| 3315 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3316 results = self.server.patch_element('issue', issue_id, form) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3317 self.assertEqual(self.dummy_client.response_code, 412) |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3318 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3319 results = results['data'] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3320 self.assertEqual(self.dummy_client.response_code, 200) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3321 self.assertEqual(results['attributes']['title'], 'foo') |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3322 self.assertEqual(len(results['attributes']['nosy']), 2) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3323 self.assertEqual(results['attributes']['nosy'], ['1', '2']) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3324 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3325 # remove the nosy list and the title |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3326 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3327 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3328 self.db.config['WEB_SECRET_KEY']) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3329 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3330 cgi.MiniFieldStorage('@op', 'remove'), |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3331 cgi.MiniFieldStorage('nosy', ''), |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3332 cgi.MiniFieldStorage('title', ''), |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3333 cgi.MiniFieldStorage('@etag', etag) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3334 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3335 results = self.server.patch_element('issue', issue_id, form) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3336 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 3337 |
| 3338 # verify the result | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3339 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
3340 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
3341 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 3342 self.assertEqual(results['attributes']['title'], None) |
| 3343 self.assertEqual(len(results['attributes']['nosy']), 0) | |
| 3344 self.assertEqual(results['attributes']['nosy'], []) | |
| 3345 | |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3346 # try to remove a protected prop. It should fail. |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3347 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3348 self.db.config['WEB_SECRET_KEY']) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3349 form = cgi.FieldStorage() |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3350 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3351 cgi.MiniFieldStorage('@op', 'remove'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3352 cgi.MiniFieldStorage('creator', '2'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3353 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3354 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3355 results = self.server.patch_element('issue', issue_id, form) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3356 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3357 'msg': KeyError('"creator", "actor", "creation" and "activity" are reserved',)}} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3358 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3359 self.assertEqual(results['error']['status'], |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3360 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3361 self.assertEqual(type(results['error']['msg']), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3362 type(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3363 self.assertEqual(str(results['error']['msg']), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3364 str(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3365 self.assertEqual(self.dummy_client.response_code, 400) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3366 |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3367 # try to remove a required prop. it should fail |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3368 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3369 self.db.config['WEB_SECRET_KEY']) |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3370 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3371 cgi.MiniFieldStorage('@op', 'remove'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3372 cgi.MiniFieldStorage('requireme', ''), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3373 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3374 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3375 results = self.server.patch_element('issue', issue_id, form) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3376 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3377 'msg': UsageError("Attribute 'requireme' is required by class issue and can not be removed.") |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3378 }} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3379 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3380 self.assertEqual(results['error']['status'], |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3381 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3382 self.assertEqual(type(results['error']['msg']), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3383 type(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3384 self.assertEqual(str(results['error']['msg']), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3385 str(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3386 self.assertEqual(self.dummy_client.response_code, 400) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
3387 |
|
5599
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3388 def testPatchAction(self): |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3389 """ |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3390 Test Patch Action 'Action' |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3391 """ |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3392 # create a new issue with userid 1 and 2 in the nosy list |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3393 issue_id = self.db.issue.create(title='foo') |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3394 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3395 # fail to execute action retire |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3396 # no etag |
|
5599
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3397 form = cgi.FieldStorage() |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3398 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3399 cgi.MiniFieldStorage('@op', 'action'), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3400 cgi.MiniFieldStorage('@action_name', 'retire') |
|
5599
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3401 ] |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3402 results = self.server.patch_element('issue', issue_id, form) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3403 self.assertEqual(self.dummy_client.response_code, 412) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3404 self.assertFalse(self.db.issue.is_retired(issue_id)) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3405 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3406 # execute action retire |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3407 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3408 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3409 self.db.config['WEB_SECRET_KEY']) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3410 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3411 cgi.MiniFieldStorage('@op', 'action'), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3412 cgi.MiniFieldStorage('@action_name', 'retire'), |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3413 cgi.MiniFieldStorage('@etag', etag) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3414 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3415 results = self.server.patch_element('issue', issue_id, form) |
|
5599
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3416 self.assertEqual(self.dummy_client.response_code, 200) |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3417 |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3418 # verify the result |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3419 self.assertTrue(self.db.issue.is_retired(issue_id)) |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
3420 |
|
5747
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3421 # execute action restore |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3422 form = cgi.FieldStorage() |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3423 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3424 self.db.config['WEB_SECRET_KEY']) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3425 form.list = [ |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3426 cgi.MiniFieldStorage('@op', 'action'), |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3427 cgi.MiniFieldStorage('@action_name', 'restore'), |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3428 cgi.MiniFieldStorage('@etag', etag) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3429 ] |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3430 results = self.server.patch_element('issue', issue_id, form) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3431 self.assertEqual(self.dummy_client.response_code, 200) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3432 |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3433 # verify the result |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3434 self.assertTrue(not self.db.issue.is_retired(issue_id)) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3435 |
|
6318
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3436 def testPatchBadAction(self): |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3437 """ |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3438 Test Patch Action 'Unknown' |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3439 """ |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3440 # create a new issue with userid 1 and 2 in the nosy list |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3441 issue_id = self.db.issue.create(title='foo') |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3442 |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3443 # execute action retire |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3444 form = cgi.FieldStorage() |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3445 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3446 self.db.config['WEB_SECRET_KEY']) |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3447 form.list = [ |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3448 cgi.MiniFieldStorage('@op', 'action'), |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3449 cgi.MiniFieldStorage('@action_name', 'unknown'), |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3450 cgi.MiniFieldStorage('@etag', etag) |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3451 ] |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3452 results = self.server.patch_element('issue', issue_id, form) |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3453 self.assertEqual(self.dummy_client.response_code, 400) |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3454 # verify the result, note order of allowed elements changes |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3455 # for python2/3 so just check prefix. |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3456 self.assertIn('action "unknown" is not supported, allowed: ', |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3457 results['error']['msg'].args[0]) |
|
ec853cef2f09
Add test for invaild action in rest.py patch_element.
John Rouillard <rouilj@ieee.org>
parents:
6317
diff
changeset
|
3458 |
|
5595
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3459 def testPatchRemove(self): |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3460 """ |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3461 Test Patch Action 'Remove' only some element from a list |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3462 """ |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3463 # create a new issue with userid 1, 2, 3 in the nosy list |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3464 issue_id = self.db.issue.create(title='foo', nosy=['1', '2', '3']) |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3465 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3466 # fail to remove the nosy list and the title |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3467 # no etag |
|
5595
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3468 form = cgi.FieldStorage() |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3469 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3470 cgi.MiniFieldStorage('@op', 'remove'), |
|
5595
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3471 cgi.MiniFieldStorage('nosy', '1, 2'), |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3472 ] |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3473 results = self.server.patch_element('issue', issue_id, form) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3474 self.assertEqual(self.dummy_client.response_code, 412) |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3475 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3476 results = results['data'] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3477 self.assertEqual(self.dummy_client.response_code, 200) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3478 self.assertEqual(len(results['attributes']['nosy']), 3) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3479 self.assertEqual(results['attributes']['nosy'], ['1', '2', '3']) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3480 |
|
5747
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3481 # remove 1 and 2 from the nosy list |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3482 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3483 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
3484 self.db.config['WEB_SECRET_KEY']) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3485 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3486 cgi.MiniFieldStorage('@op', 'remove'), |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3487 cgi.MiniFieldStorage('nosy', '1, 2'), |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3488 cgi.MiniFieldStorage('@etag', etag) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3489 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
3490 results = self.server.patch_element('issue', issue_id, form) |
|
5595
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3491 self.assertEqual(self.dummy_client.response_code, 200) |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3492 |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3493 # verify the result |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
3494 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
5595
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3495 results = results['data'] |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3496 self.assertEqual(self.dummy_client.response_code, 200) |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3497 self.assertEqual(len(results['attributes']['nosy']), 1) |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3498 self.assertEqual(results['attributes']['nosy'], ['3']) |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
3499 |
|
5747
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3500 # delete last element: 3 |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3501 etag = calculate_etag(self.db.issue.getnode(issue_id), |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3502 self.db.config['WEB_SECRET_KEY']) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3503 form = cgi.FieldStorage() |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3504 form.list = [ |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3505 cgi.MiniFieldStorage('@op', 'remove'), |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3506 cgi.MiniFieldStorage('data', '3'), |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3507 cgi.MiniFieldStorage('@etag', etag) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3508 ] |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3509 results = self.server.patch_attribute('issue', issue_id, 'nosy', form) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3510 self.assertEqual(self.dummy_client.response_code, 200) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3511 |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3512 # verify the result |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3513 results = self.server.get_element('issue', issue_id, self.terse_form) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3514 results = results['data'] |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3515 self.assertEqual(self.dummy_client.response_code, 200) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3516 self.assertEqual(len(results['attributes']['nosy']), 0) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3517 self.assertListEqual(results['attributes']['nosy'], []) |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
3518 |
|
7156
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3519 def testRestExposeHeaders(self): |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3520 |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3521 local_client = self.server.client |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3522 body = b'{ "data": "Joe Doe 1" }' |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3523 env = { "CONTENT_TYPE": "application/json", |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3524 "CONTENT_LENGTH": len(body), |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3525 "REQUEST_METHOD": "PUT", |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3526 "HTTP_ORIGIN": "http://tracker.example" |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3527 } |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3528 local_client.env.update(env) |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3529 |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3530 local_client.db.config["WEB_ALLOWED_API_ORIGINS"] = " * " |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3531 |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3532 headers={"accept": "application/json; version=1", |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3533 "content-type": env['CONTENT_TYPE'], |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3534 "content-length": env['CONTENT_LENGTH'], |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3535 "origin": env['HTTP_ORIGIN'] |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3536 } |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3537 self.headers=headers |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3538 # we need to generate a FieldStorage the looks like |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3539 # FieldStorage(None, None, 'string') rather than |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3540 # FieldStorage(None, None, []) |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3541 body_file=BytesIO(body) # FieldStorage needs a file |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3542 form = client.BinaryFieldStorage(body_file, |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3543 headers=headers, |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3544 environ=env) |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3545 local_client.request.headers.get=self.get_header |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3546 results = self.server.dispatch('PUT', |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3547 "/rest/data/user/%s/realname"%self.joeid, |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3548 form) |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3549 |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3550 for header in [ "X-RateLimit-Limit", |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3551 "X-RateLimit-Remaining", |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3552 "X-RateLimit-Reset", |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3553 "X-RateLimit-Limit-Period", |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3554 "Retry-After", |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3555 "Sunset", |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3556 "Allow", |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3557 ]: |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3558 self.assertIn( |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3559 header, |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3560 self.server.client.additional_headers[ |
|
6f09103a6522
[issue2551263] expose headers to rest clients
John Rouillard <rouilj@ieee.org>
parents:
7155
diff
changeset
|
3561 "Access-Control-Expose-Headers"]) |
|
7155
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3562 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3563 def testRestMatchWildcardOrigin(self): |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3564 # cribbed from testDispatch #1 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3565 # PUT: joe's 'realname' using json data. |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3566 # simulate: /rest/data/user/<id>/realname |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3567 # use etag in header |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3568 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3569 # verify that credential header is missing, valid allow origin |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3570 # header and vary includes origin. |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3571 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3572 local_client = self.server.client |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3573 etag = calculate_etag(self.db.user.getnode(self.joeid), |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3574 self.db.config['WEB_SECRET_KEY']) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3575 body = b'{ "data": "Joe Doe 1" }' |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3576 env = { "CONTENT_TYPE": "application/json", |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3577 "CONTENT_LENGTH": len(body), |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3578 "REQUEST_METHOD": "PUT", |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3579 "HTTP_ORIGIN": "https://bad.origin" |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3580 } |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3581 local_client.env.update(env) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3582 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3583 local_client.db.config["WEB_ALLOWED_API_ORIGINS"] = " * " |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3584 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3585 headers={"accept": "application/json; version=1", |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3586 "content-type": env['CONTENT_TYPE'], |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3587 "content-length": env['CONTENT_LENGTH'], |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3588 "if-match": etag, |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3589 "origin": env['HTTP_ORIGIN'] |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3590 } |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3591 self.headers=headers |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3592 # we need to generate a FieldStorage the looks like |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3593 # FieldStorage(None, None, 'string') rather than |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3594 # FieldStorage(None, None, []) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3595 body_file=BytesIO(body) # FieldStorage needs a file |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3596 form = client.BinaryFieldStorage(body_file, |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3597 headers=headers, |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3598 environ=env) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3599 local_client.request.headers.get=self.get_header |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3600 results = self.server.dispatch('PUT', |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3601 "/rest/data/user/%s/realname"%self.joeid, |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3602 form) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3603 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3604 self.assertNotIn("Access-Control-Allow-Credentials", |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3605 local_client.additional_headers) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3606 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3607 self.assertIn("Access-Control-Allow-Origin", |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3608 local_client.additional_headers) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3609 self.assertEqual( |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3610 headers['origin'], |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3611 local_client.additional_headers["Access-Control-Allow-Origin"]) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3612 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3613 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3614 self.assertIn("Vary", local_client.additional_headers) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3615 self.assertIn("Origin", |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3616 local_client.additional_headers['Vary']) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3617 |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3618 self.assertEqual(local_client.response_code, 200) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3619 results = self.server.get_element('user', self.joeid, self.empty_form) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3620 self.assertEqual(self.dummy_client.response_code, 200) |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3621 self.assertEqual(results['data']['attributes']['realname'], |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3622 'Joe Doe 1') |
|
89a59e46b3af
improve REST interface security
John Rouillard <rouilj@ieee.org>
parents:
6660
diff
changeset
|
3623 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3624 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3625 def test_expired_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3626 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3627 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3628 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3629 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3630 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3631 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3632 secret = self.db.config.WEB_JWT_SECRET |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3633 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3634 # verify library and tokens are correct |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3635 self.assertRaises(jwt.exceptions.InvalidTokenError, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3636 jwt.decode, self.jwt['expired'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3637 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3638 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3639 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3640 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3641 result = jwt.decode(self.jwt['user'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3642 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3643 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3644 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3645 self.assertEqual(self.claim['user'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3646 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3647 result = jwt.decode(self.jwt['user:email'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3648 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3649 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3650 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3651 self.assertEqual(self.claim['user:email'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3652 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3653 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3654 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3655 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3656 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3657 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3658 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3659 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3660 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3661 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3662 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3663 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3664 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3665 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3666 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3667 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3668 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3669 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3670 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3671 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3672 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3673 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3674 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3675 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3676 # set up for expired token first |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3677 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['expired'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3678 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3679 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3680 # this will be the admin still as auth failed |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3681 self.assertEqual('1', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3682 self.assertEqual(out[0], b'Invalid Login - Signature has expired') |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3683 del(out[0]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3684 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3685 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3686 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3687 def test_user_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3688 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3689 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3690 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3691 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3692 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3693 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3694 secret = self.db.config.WEB_JWT_SECRET |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3695 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3696 # verify library and tokens are correct |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3697 self.assertRaises(jwt.exceptions.InvalidTokenError, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3698 jwt.decode, self.jwt['expired'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3699 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3700 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3701 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3702 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3703 result = jwt.decode(self.jwt['user'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3704 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3705 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3706 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3707 self.assertEqual(self.claim['user'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3708 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3709 result = jwt.decode(self.jwt['user:email'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3710 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3711 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3712 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3713 self.assertEqual(self.claim['user:email'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3714 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3715 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3716 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3717 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3718 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3719 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3720 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3721 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3722 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3723 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3724 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3725 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3726 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3727 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3728 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3729 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3730 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3731 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3732 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3733 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3734 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3735 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3736 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3737 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3738 # set up for standard user role token |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3739 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['user'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3740 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3741 print(out[0]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3742 json_dict = json.loads(b2s(out[0])) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3743 print(json_dict) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3744 # user will be joe id 3 as auth works |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3745 self.assertTrue('3', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3746 # there should be three items in the collection admin, anon, and joe |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3747 self.assertEqual(3, len(json_dict['data']['collection'])) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3748 # since this token has no access to email addresses, only joe |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3749 # should have email addresses. Order is by id by default. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3750 self.assertFalse('address' in json_dict['data']['collection'][0]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3751 self.assertFalse('address' in json_dict['data']['collection'][1]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3752 self.assertTrue('address' in json_dict['data']['collection'][2]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3753 del(out[0]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3754 self.db.setCurrentUser('admin') |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3755 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3756 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3757 def test_user_email_jwt(self): |
|
5879
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3758 '''tests "Rest Access" permission present case''' |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3759 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3760 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3761 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3762 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3763 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3764 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3765 secret = self.db.config.WEB_JWT_SECRET |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3766 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3767 # verify library and tokens are correct |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3768 self.assertRaises(jwt.exceptions.InvalidTokenError, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3769 jwt.decode, self.jwt['expired'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3770 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3771 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3772 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3773 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3774 result = jwt.decode(self.jwt['user'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3775 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3776 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3777 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3778 self.assertEqual(self.claim['user'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3779 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3780 result = jwt.decode(self.jwt['user:email'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3781 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3782 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3783 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3784 self.assertEqual(self.claim['user:email'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3785 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3786 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3787 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3788 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3789 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3790 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3791 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3792 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3793 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3794 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3795 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3796 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3797 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3798 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3799 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3800 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3801 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3802 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3803 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3804 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3805 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3806 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3807 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3808 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3809 # set up for limited user:email role token |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3810 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['user:email'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3811 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3812 json_dict = json.loads(b2s(out[0])) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3813 print(json_dict) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3814 # user will be joe id 3 as auth works |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3815 self.assertTrue('3', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3816 # there should be three items in the collection admin, anon, and joe |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3817 self.assertEqual(3, len(json_dict['data']['collection'])) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3818 # However this token has access to email addresses, so all three |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3819 # should have email addresses. Order is by id by default. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3820 self.assertTrue('address' in json_dict['data']['collection'][0]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3821 self.assertTrue('address' in json_dict['data']['collection'][1]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3822 self.assertTrue('address' in json_dict['data']['collection'][2]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3823 |
|
5879
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3824 @skip_jwt |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3825 def test_user_emailnorest_jwt(self): |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3826 '''tests "Rest Access" permission missing case''' |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3827 # self.dummy_client.main() closes database, so |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3828 # we need a new test with setup called for each test |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3829 out = [] |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3830 def wh(s): |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3831 out.append(s) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3832 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3833 secret = self.db.config.WEB_JWT_SECRET |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3834 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3835 # verify library and tokens are correct |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3836 self.assertRaises(jwt.exceptions.InvalidTokenError, |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3837 jwt.decode, self.jwt['expired'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3838 secret, algorithms=['HS256'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3839 audience=self.db.config.TRACKER_WEB, |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3840 issuer=self.db.config.TRACKER_WEB) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3841 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3842 result = jwt.decode(self.jwt['user'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3843 secret, algorithms=['HS256'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3844 audience=self.db.config.TRACKER_WEB, |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3845 issuer=self.db.config.TRACKER_WEB) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3846 self.assertEqual(self.claim['user'],result) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3847 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3848 result = jwt.decode(self.jwt['user:email'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3849 secret, algorithms=['HS256'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3850 audience=self.db.config.TRACKER_WEB, |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3851 issuer=self.db.config.TRACKER_WEB) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3852 self.assertEqual(self.claim['user:email'],result) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3853 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3854 # set environment for all jwt tests |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3855 env = { |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3856 'PATH_INFO': 'rest/data/user', |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3857 'HTTP_HOST': 'localhost', |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3858 'TRACKER_NAME': 'rounduptest', |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3859 "REQUEST_METHOD": "GET" |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3860 } |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3861 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3862 [], None) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3863 self.dummy_client.db = self.db |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3864 self.dummy_client.request.headers.get = self.get_header |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3865 self.empty_form = cgi.FieldStorage() |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3866 self.terse_form = cgi.FieldStorage() |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3867 self.terse_form.list = [ |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3868 cgi.MiniFieldStorage('@verbose', '0'), |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3869 ] |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3870 self.dummy_client.form = cgi.FieldStorage() |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3871 self.dummy_client.form.list = [ |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3872 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3873 ] |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3874 # accumulate json output for further analysis |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3875 self.dummy_client.write = wh |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3876 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3877 # set up for limited user:email role token |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3878 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['user:emailnorest'] |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3879 self.dummy_client.main() |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3880 json_dict = json.loads(b2s(out[0])) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3881 # user will be joe id 3 as auth works |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3882 self.assertTrue('1', self.db.getuid()) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3883 { "error": { "status": 403, "msg": "Forbidden." } } |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3884 self.assertTrue('error' in json_dict) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3885 self.assertTrue(json_dict['error']['status'], 403) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3886 self.assertTrue(json_dict['error']['msg'], "Forbidden.") |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3887 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3888 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3889 def test_disabled_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3890 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3891 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3892 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3893 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3894 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3895 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3896 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3897 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3898 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3899 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3900 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3901 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3902 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3903 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3904 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3905 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3906 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3907 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3908 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3909 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3910 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3911 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3912 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3913 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3914 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3915 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3916 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3917 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3918 # disable jwt validation by making secret too short |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3919 # use the default value for this in configure.py. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3920 self.db.config['WEB_JWT_SECRET'] = "disabled" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3921 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['user'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3922 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3923 # user will be 1 as there is no auth |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3924 self.assertTrue('1', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3925 self.assertEqual(out[0], b'Invalid Login - Support for jwt disabled by admin.') |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3926 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3927 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3928 def test_bad_issue_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3929 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3930 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3931 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3932 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3933 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3934 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3935 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3936 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3937 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3938 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3939 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3940 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3941 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3942 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3943 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3944 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3945 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3946 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3947 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3948 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3949 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3950 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3951 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3952 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3953 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3954 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3955 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3956 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3957 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['badiss'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3958 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3959 # user will be 1 as there is no auth |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3960 self.assertTrue('1', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3961 self.assertEqual(out[0], b'Invalid Login - Invalid issuer') |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3962 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3963 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3964 def test_bad_audience_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3965 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3966 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3967 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3968 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3969 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3970 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3971 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3972 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3973 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3974 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3975 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3976 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3977 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3978 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3979 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3980 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3981 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3982 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3983 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3984 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3985 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3986 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3987 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3988 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3989 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3990 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3991 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3992 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3993 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['badaud'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3994 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3995 # user will be 1 as there is no auth |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3996 self.assertTrue('1', self.db.getuid()) |
|
7389
613f822f1f24
Support pyjwt-2.7.0 in test_bad_audience_jwt
John Rouillard <rouilj@ieee.org>
parents:
7372
diff
changeset
|
3997 self.assertIn(out[0], [b'Invalid Login - Invalid audience', |
|
613f822f1f24
Support pyjwt-2.7.0 in test_bad_audience_jwt
John Rouillard <rouilj@ieee.org>
parents:
7372
diff
changeset
|
3998 b"Invalid Login - Audience doesn't match"]) |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3999 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4000 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4001 def test_bad_roles_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4002 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4003 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4004 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4005 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4006 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4007 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4008 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4009 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4010 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4011 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4012 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4013 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4014 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4015 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4016 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4017 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4018 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4019 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4020 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4021 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4022 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4023 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4024 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4025 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4026 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4027 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4028 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4029 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4030 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['badroles'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4031 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4032 # user will be 1 as there is no auth |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4033 self.assertTrue('1', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4034 self.assertEqual(out[0], b'Invalid Login - Token roles are invalid.') |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4035 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4036 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4037 def test_bad_subject_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4038 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4039 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4040 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4041 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4042 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4043 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4044 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4045 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4046 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4047 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4048 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4049 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4050 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4051 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4052 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4053 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4054 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4055 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4056 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4057 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4058 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4059 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4060 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4061 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4062 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4063 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4064 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4065 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4066 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['badsub'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4067 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4068 # user will be 1 as there is no auth |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4069 self.assertTrue('1', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
4070 self.assertEqual(out[0], b'Invalid Login - Token subject is invalid.') |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
4071 |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
4072 def get_obj(path, id): |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
4073 return { |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
4074 'id': id, |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
4075 'link': path + id |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
4076 } |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
4077 |
| 5583 | 4078 if __name__ == '__main__': |
| 4079 runner = unittest.TextTestRunner() | |
| 4080 unittest.main(testRunner=runner) |
