Skip to content

Commit 0909755

Browse files
committed
Merge pull request #1584 from josenavas/artifact-oauth
Plugins oauth2
2 parents 19dfe07 + 64e0713 commit 0909755

File tree

11 files changed

+2729
-3622
lines changed

11 files changed

+2729
-3622
lines changed

qiita_db/handlers/tests/oauthbase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ def setUp(self):
99
self.header = {'Authorization': 'Bearer ' + self.token}
1010
r_client.hset(self.token, 'timestamp', '12/12/12 12:12:00')
1111
r_client.hset(self.token, 'grant_type', 'client')
12-
r_client.expire(self.token, 2)
12+
r_client.expire(self.token, 20)
1313
super(OauthTestingBase, self).setUp()

qiita_db/handlers/tests/test_oauth2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_authenticate_client_header(self):
9595
obs_body = loads(obs.body)
9696
exp = {'access_token': 'token',
9797
'token_type': 'Bearer',
98-
'expires_in': '3600'}
98+
'expires_in': 3600}
9999
self.assertItemsEqual(obs_body.keys(), exp.keys())
100100
self.assertEqual(obs_body['token_type'], exp['token_type'])
101101
self.assertEqual(obs_body['expires_in'], exp['expires_in'])
@@ -122,7 +122,7 @@ def test_authenticate_client_post(self):
122122
obs_body = loads(obs.body)
123123
exp = {'access_token': 'placeholder',
124124
'token_type': 'Bearer',
125-
'expires_in': '3600'}
125+
'expires_in': 3600}
126126
self.assertItemsEqual(obs_body.keys(), exp.keys())
127127
self.assertEqual(obs_body['token_type'], exp['token_type'])
128128
self.assertEqual(obs_body['expires_in'], exp['expires_in'])
@@ -215,7 +215,7 @@ def test_authenticate_password(self):
215215
obs_body = loads(obs.body)
216216
exp = {'access_token': 'placeholder',
217217
'token_type': 'Bearer',
218-
'expires_in': '3600'}
218+
'expires_in': 3600}
219219
self.assertItemsEqual(obs_body.keys(), exp.keys())
220220
self.assertEqual(obs_body['token_type'], exp['token_type'])
221221
self.assertEqual(obs_body['expires_in'], exp['expires_in'])
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
-- Dec 5, 2015
22
-- Adds table needed for oauth2 authentication
33

4-
CREATE TABLE qiita.oauth_identifiers (
4+
CREATE TABLE qiita.oauth_identifiers (
55
client_id varchar(50) NOT NULL,
66
client_secret varchar(255),
77
CONSTRAINT pk_oauth2 PRIMARY KEY ( client_id )
8-
);
8+
);
9+
10+
CREATE TABLE qiita.oauth_software (
11+
software_id bigint NOT NULL,
12+
client_id varchar NOT NULL,
13+
CONSTRAINT idx_oauth_software PRIMARY KEY ( software_id, client_id )
14+
) ;
15+
CREATE INDEX idx_oauth_software_software ON qiita.oauth_software ( software_id ) ;
16+
CREATE INDEX idx_oauth_software_client ON qiita.oauth_software ( client_id ) ;
17+
ALTER TABLE qiita.oauth_software ADD CONSTRAINT fk_oauth_software_software FOREIGN KEY ( software_id ) REFERENCES qiita.software( software_id ) ;
18+
ALTER TABLE qiita.oauth_software ADD CONSTRAINT fk_oauth_software FOREIGN KEY ( client_id ) REFERENCES qiita.oauth_identifiers( client_id ) ;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from random import SystemRandom
2+
from string import ascii_letters, digits
3+
4+
from qiita_db.sql_connection import TRN
5+
6+
pool = ascii_letters + digits
7+
client_id = ''.join([SystemRandom().choice(pool) for _ in range(50)])
8+
client_secret = ''.join([SystemRandom().choice(pool) for _ in range(255)])
9+
10+
with TRN:
11+
sql = """INSERT INTO qiita.oauth_identifiers (client_id, client_secret)
12+
VALUES (%s, %s)"""
13+
TRN.add(sql, [client_id, client_secret])
14+
15+
sql = """INSERT INTO qiita.oauth_software (software_id, client_id)
16+
VALUES (%s, %s)"""
17+
TRN.add(sql, [1, client_id])
18+
TRN.execute()

qiita_db/support_files/qiita-db.dbs

Lines changed: 80 additions & 38 deletions
Large diffs are not rendered by default.

qiita_db/support_files/qiita-db.html

Lines changed: 2521 additions & 3575 deletions
Large diffs are not rendered by default.

qiita_plugins/target_gene/tgp/split_libraries/tests/test_util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@
2121

2222

2323
class UtilTests(TestCase):
24+
@httpretty.activate
2425
def setUp(self):
26+
httpretty.register_uri(
27+
httpretty.POST,
28+
"https://test_server.com/qiita_db/authenticate/",
29+
body='{"access_token": "token", "token_type": "Bearer", '
30+
'"expires_in": "3600"}')
31+
2532
self.qclient = QiitaClient("https://test_server.com")
2633
self._clean_up_files = []
2734

qiita_plugins/target_gene/tgp/support_files/config_file.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
# If the Qiita server certificate is not a valid certificate,
1515
# put here the path to the certificate so it can be verified
1616
SERVER_CERT =
17+
18+
# Oauth2 plugin configuration
19+
CLIENT_ID =
20+
CLIENT_SECRET =

qiita_plugins/target_gene/tgp/tests/test_qiita_client.py

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717

1818

1919
class QiitaClientTests(TestCase):
20+
@httpretty.activate
2021
def setUp(self):
22+
httpretty.register_uri(
23+
httpretty.POST,
24+
"https://test_server.com/qiita_db/authenticate/",
25+
body='{"access_token": "token", "token_type": "Bearer", '
26+
'"expires_in": "3600"}')
2127
self.tester = QiitaClient("https://test_server.com")
2228
self._clean_up_files = []
2329
self._old_fp = environ.get('QP_TARGET_GENE_CONFIG_FP')
@@ -31,24 +37,40 @@ def tearDown(self):
3137
else:
3238
del environ['QP_TARGET_GENE_CONFIG_FP']
3339

40+
@httpretty.activate
3441
def test_init(self):
42+
httpretty.register_uri(
43+
httpretty.POST,
44+
"https://test_server.com/qiita_db/authenticate/",
45+
body='{"access_token": "token", "token_type": "Bearer", '
46+
'"expires_in": "3600"}')
3547
obs = QiitaClient("https://test_server.com")
3648
self.assertEqual(obs._server_url, "https://test_server.com")
3749
self.assertTrue(obs._verify)
3850

51+
@httpretty.activate
3952
def test_init_cert(self):
53+
httpretty.register_uri(
54+
httpretty.POST,
55+
"https://test_server.com/qiita_db/authenticate/",
56+
body='{"access_token": "token", "token_type": "Bearer", '
57+
'"expires_in": "3600"}')
58+
fd, cert_fp = mkstemp()
59+
close(fd)
60+
with open(cert_fp, 'w') as f:
61+
f.write(CERT_FP)
4062
fd, conf_fp = mkstemp()
4163
close(fd)
4264
with open(conf_fp, 'w') as f:
43-
f.write(CONF_FP)
65+
f.write(CONF_FP % cert_fp)
4466

4567
self._clean_up_files.append(conf_fp)
4668

4769
environ['QP_TARGET_GENE_CONFIG_FP'] = conf_fp
4870
obs = QiitaClient("https://test_server.com")
4971

5072
self.assertEqual(obs._server_url, "https://test_server.com")
51-
self.assertEqual(obs._verify, "/path/to/test_certificate.crt")
73+
self.assertEqual(obs._verify, cert_fp)
5274

5375
@httpretty.activate
5476
def test_get(self):
@@ -100,8 +122,33 @@ def test_post_error(self):
100122
[main]
101123
# If the Qiita server certificate is not a valid certificate,
102124
# put here the path to the certificate so it can be verified
103-
SERVER_CERT = /path/to/test_certificate.crt
125+
SERVER_CERT = %s
126+
127+
# Oauth2 plugin configuration
128+
CLIENT_ID = client_id
129+
CLIENT_SECRET = client_secret
104130
"""
105131

132+
CERT_FP = """-----BEGIN CERTIFICATE-----
133+
MIIDVjCCAj4CCQCP4XnDqToF2zANBgkqhkiG9w0BAQUFADBtMQswCQYDVQQGEwJV
134+
UzETMBEGA1UECBMKQ2FsaWZvcm5pYTESMBAGA1UEBxMJU2FuIERpZWdvMQ0wCwYD
135+
VQQKEwRVQ1NEMRIwEAYDVQQLEwlLbmlnaHRMYWIxEjAQBgNVBAMTCWxvY2FsaG9z
136+
dDAeFw0xNTEyMTgyMjE3MzBaFw0xNjEyMTcyMjE3MzBaMG0xCzAJBgNVBAYTAlVT
137+
MRMwEQYDVQQIEwpDYWxpZm9ybmlhMRIwEAYDVQQHEwlTYW4gRGllZ28xDTALBgNV
138+
BAoTBFVDU0QxEjAQBgNVBAsTCUtuaWdodExhYjESMBAGA1UEAxMJbG9jYWxob3N0
139+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt1ggW4M/l3Wpru4+2Cro
140+
nnqaUWD0ImLnkdAbmDjhGiCdKqdb8yzLeKipGaRY383gd5vMWHsKB1I3t+EzFWiY
141+
fxd12Evx6MUIXVZSkdConk+8xlmJ5ba1Hgy7qzErY7+HOtgqm1ylyqTuOZyv3Umv
142+
0W6ETLVz/alfzxTlqAkvuJn7I7RrbY81I3b5SOUxJTtj9pPwkZtVOD0ha3FH0LBu
143+
lE4oi6rQQhzIbUDWLITZRCteplV5ikbC3JqaJ7pDiYnOIPnRR0UF+xdyTiOvSNH8
144+
WrKuAdGGN+90PDt8fgQOwptE5l/RGyoJ2on7nlSj5crDtYzXXDYw0DCzuFG12nZV
145+
FwIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQBTQJ8WYpSfsXsgmDa2uIYX5E+8ECGn
146+
patQJuxYfOEp9knnBBe+QcaBMY6E7uH6EZz2QwS/gdhfY8e8QXw9sh9ZrQKQlIAK
147+
Q5l5qxAtek0C90qdseYWoomBhpmqMUicF0OgecbdZ4X6Tfc4hvN5IXUTMn9ZJEaV
148+
fduah3c7xEkSbHQl6iHnJswNKTc7Amm+BIwuYJjCZxVgKxAgvYzzg/TFU03gqzfE
149+
h7ARs1p4WdHH+WTMqCZq8+sju3Lum4uwjYaiLaFE7psDkWWAYOu6Jv/o0V1zER/S
150+
LzNaDfkm5kq4VURhPMQzdAiVdiTNKDFnLB3erg6wG95q5OiGNO1WYSw2
151+
-----END CERTIFICATE-----"""
152+
106153
if __name__ == '__main__':
107154
main()

qiita_plugins/target_gene/tgp/tests/test_util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717

1818

1919
class UtilTests(TestCase):
20+
@httpretty.activate
2021
def setUp(self):
22+
httpretty.register_uri(
23+
httpretty.POST,
24+
"https://test_server.com/qiita_db/authenticate/",
25+
body='{"access_token": "token", "token_type": "Bearer", '
26+
'"expires_in": "3600"}')
2127
self.qclient = QiitaClient("https://test_server.com")
2228

2329
def test_system_call(self):

0 commit comments

Comments
 (0)