Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qiita_db/handlers/tests/oauthbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def setUp(self):
self.header = {'Authorization': 'Bearer ' + self.token}
r_client.hset(self.token, 'timestamp', '12/12/12 12:12:00')
r_client.hset(self.token, 'grant_type', 'client')
r_client.expire(self.token, 2)
r_client.expire(self.token, 20)
super(OauthTestingBase, self).setUp()
6 changes: 3 additions & 3 deletions qiita_db/handlers/tests/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_authenticate_client_header(self):
obs_body = loads(obs.body)
exp = {'access_token': 'token',
'token_type': 'Bearer',
'expires_in': '3600'}
'expires_in': 3600}
self.assertItemsEqual(obs_body.keys(), exp.keys())
self.assertEqual(obs_body['token_type'], exp['token_type'])
self.assertEqual(obs_body['expires_in'], exp['expires_in'])
Expand All @@ -122,7 +122,7 @@ def test_authenticate_client_post(self):
obs_body = loads(obs.body)
exp = {'access_token': 'placeholder',
'token_type': 'Bearer',
'expires_in': '3600'}
'expires_in': 3600}
self.assertItemsEqual(obs_body.keys(), exp.keys())
self.assertEqual(obs_body['token_type'], exp['token_type'])
self.assertEqual(obs_body['expires_in'], exp['expires_in'])
Expand Down Expand Up @@ -215,7 +215,7 @@ def test_authenticate_password(self):
obs_body = loads(obs.body)
exp = {'access_token': 'placeholder',
'token_type': 'Bearer',
'expires_in': '3600'}
'expires_in': 3600}
self.assertItemsEqual(obs_body.keys(), exp.keys())
self.assertEqual(obs_body['token_type'], exp['token_type'])
self.assertEqual(obs_body['expires_in'], exp['expires_in'])
Expand Down
14 changes: 12 additions & 2 deletions qiita_db/support_files/patches/34.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
-- Dec 5, 2015
-- Adds table needed for oauth2 authentication

CREATE TABLE qiita.oauth_identifiers (
CREATE TABLE qiita.oauth_identifiers (
client_id varchar(50) NOT NULL,
client_secret varchar(255),
CONSTRAINT pk_oauth2 PRIMARY KEY ( client_id )
);
);

CREATE TABLE qiita.oauth_software (
software_id bigint NOT NULL,
client_id varchar NOT NULL,
CONSTRAINT idx_oauth_software PRIMARY KEY ( software_id, client_id )
) ;
CREATE INDEX idx_oauth_software_software ON qiita.oauth_software ( software_id ) ;
CREATE INDEX idx_oauth_software_client ON qiita.oauth_software ( client_id ) ;
ALTER TABLE qiita.oauth_software ADD CONSTRAINT fk_oauth_software_software FOREIGN KEY ( software_id ) REFERENCES qiita.software( software_id ) ;
ALTER TABLE qiita.oauth_software ADD CONSTRAINT fk_oauth_software FOREIGN KEY ( client_id ) REFERENCES qiita.oauth_identifiers( client_id ) ;
18 changes: 18 additions & 0 deletions qiita_db/support_files/patches/python_patches/34.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from random import SystemRandom
from string import ascii_letters, digits

from qiita_db.sql_connection import TRN

pool = ascii_letters + digits
client_id = ''.join([SystemRandom().choice(pool) for _ in range(50)])
client_secret = ''.join([SystemRandom().choice(pool) for _ in range(255)])

with TRN:
sql = """INSERT INTO qiita.oauth_identifiers (client_id, client_secret)
VALUES (%s, %s)"""
TRN.add(sql, [client_id, client_secret])

sql = """INSERT INTO qiita.oauth_software (software_id, client_id)
VALUES (%s, %s)"""
TRN.add(sql, [1, client_id])
TRN.execute()
118 changes: 80 additions & 38 deletions qiita_db/support_files/qiita-db.dbs

Large diffs are not rendered by default.

6,096 changes: 2,521 additions & 3,575 deletions qiita_db/support_files/qiita-db.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@


class UtilTests(TestCase):
@httpretty.activate
def setUp(self):
httpretty.register_uri(
httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')

self.qclient = QiitaClient("https://test_server.com")
self._clean_up_files = []

Expand Down
4 changes: 4 additions & 0 deletions qiita_plugins/target_gene/tgp/support_files/config_file.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
# If the Qiita server certificate is not a valid certificate,
# put here the path to the certificate so it can be verified
SERVER_CERT =

# Oauth2 plugin configuration
CLIENT_ID =
CLIENT_SECRET =
53 changes: 50 additions & 3 deletions qiita_plugins/target_gene/tgp/tests/test_qiita_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@


class QiitaClientTests(TestCase):
@httpretty.activate
def setUp(self):
httpretty.register_uri(
httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')
self.tester = QiitaClient("https://test_server.com")
self._clean_up_files = []
self._old_fp = environ.get('QP_TARGET_GENE_CONFIG_FP')
Expand All @@ -31,24 +37,40 @@ def tearDown(self):
else:
del environ['QP_TARGET_GENE_CONFIG_FP']

@httpretty.activate
def test_init(self):
httpretty.register_uri(
httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')
obs = QiitaClient("https://test_server.com")
self.assertEqual(obs._server_url, "https://test_server.com")
self.assertTrue(obs._verify)

@httpretty.activate
def test_init_cert(self):
httpretty.register_uri(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated from setUp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remove this one - tests fail. The other 2, however, have been removed.

httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')
fd, cert_fp = mkstemp()
close(fd)
with open(cert_fp, 'w') as f:
f.write(CERT_FP)
fd, conf_fp = mkstemp()
close(fd)
with open(conf_fp, 'w') as f:
f.write(CONF_FP)
f.write(CONF_FP % cert_fp)

self._clean_up_files.append(conf_fp)

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

self.assertEqual(obs._server_url, "https://test_server.com")
self.assertEqual(obs._verify, "/path/to/test_certificate.crt")
self.assertEqual(obs._verify, cert_fp)

@httpretty.activate
def test_get(self):
Expand Down Expand Up @@ -100,8 +122,33 @@ def test_post_error(self):
[main]
# If the Qiita server certificate is not a valid certificate,
# put here the path to the certificate so it can be verified
SERVER_CERT = /path/to/test_certificate.crt
SERVER_CERT = %s

# Oauth2 plugin configuration
CLIENT_ID = client_id
CLIENT_SECRET = client_secret
"""

CERT_FP = """-----BEGIN CERTIFICATE-----
MIIDVjCCAj4CCQCP4XnDqToF2zANBgkqhkiG9w0BAQUFADBtMQswCQYDVQQGEwJV
UzETMBEGA1UECBMKQ2FsaWZvcm5pYTESMBAGA1UEBxMJU2FuIERpZWdvMQ0wCwYD
VQQKEwRVQ1NEMRIwEAYDVQQLEwlLbmlnaHRMYWIxEjAQBgNVBAMTCWxvY2FsaG9z
dDAeFw0xNTEyMTgyMjE3MzBaFw0xNjEyMTcyMjE3MzBaMG0xCzAJBgNVBAYTAlVT
MRMwEQYDVQQIEwpDYWxpZm9ybmlhMRIwEAYDVQQHEwlTYW4gRGllZ28xDTALBgNV
BAoTBFVDU0QxEjAQBgNVBAsTCUtuaWdodExhYjESMBAGA1UEAxMJbG9jYWxob3N0
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt1ggW4M/l3Wpru4+2Cro
nnqaUWD0ImLnkdAbmDjhGiCdKqdb8yzLeKipGaRY383gd5vMWHsKB1I3t+EzFWiY
fxd12Evx6MUIXVZSkdConk+8xlmJ5ba1Hgy7qzErY7+HOtgqm1ylyqTuOZyv3Umv
0W6ETLVz/alfzxTlqAkvuJn7I7RrbY81I3b5SOUxJTtj9pPwkZtVOD0ha3FH0LBu
lE4oi6rQQhzIbUDWLITZRCteplV5ikbC3JqaJ7pDiYnOIPnRR0UF+xdyTiOvSNH8
WrKuAdGGN+90PDt8fgQOwptE5l/RGyoJ2on7nlSj5crDtYzXXDYw0DCzuFG12nZV
FwIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQBTQJ8WYpSfsXsgmDa2uIYX5E+8ECGn
patQJuxYfOEp9knnBBe+QcaBMY6E7uH6EZz2QwS/gdhfY8e8QXw9sh9ZrQKQlIAK
Q5l5qxAtek0C90qdseYWoomBhpmqMUicF0OgecbdZ4X6Tfc4hvN5IXUTMn9ZJEaV
fduah3c7xEkSbHQl6iHnJswNKTc7Amm+BIwuYJjCZxVgKxAgvYzzg/TFU03gqzfE
h7ARs1p4WdHH+WTMqCZq8+sju3Lum4uwjYaiLaFE7psDkWWAYOu6Jv/o0V1zER/S
LzNaDfkm5kq4VURhPMQzdAiVdiTNKDFnLB3erg6wG95q5OiGNO1WYSw2
-----END CERTIFICATE-----"""

if __name__ == '__main__':
main()
6 changes: 6 additions & 0 deletions qiita_plugins/target_gene/tgp/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@


class UtilTests(TestCase):
@httpretty.activate
def setUp(self):
httpretty.register_uri(
httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')
self.qclient = QiitaClient("https://test_server.com")

def test_system_call(self):
Expand Down
27 changes: 27 additions & 0 deletions scripts/qiita-test-install
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ Qiita version and configuration tests
=====================================
"""

qiita_plugins_header = """
Qiita plugins
=============
"""


def main():
system_info = [
Expand Down Expand Up @@ -416,6 +421,28 @@ def main():
if v != ('Extra info', None):
print "%*s:\t%s" % (max_len, v[0], v[1])

print qiita_plugins_header
if not psql_running:
print "PostgreSQL not running, can't retrieve plugin information"
else:
try:
import qiita_db as qdb
with qdb.sql_connection.TRN:
sql = """SELECT name, version, client_id, client_secret
FROM qiita.software
JOIN qiita.oauth_software USING (software_id)
JOIN qiita.oauth_identifiers USING (client_id)"""
qdb.sql_connection.TRN.add(sql)
res = qdb.sql_connection.TRN.execute_fetchindex()
for name, version, client_id, client_secret in res:
print "Plugin name: %s" % name
print "\tVersion: %s" % version
print "\tClient id: %s" % client_id
print "\tClient secret: %s" % client_secret
except Exception as e:
print ("An error occurred while retrieving plugin information: %s"
% str(e))

print qiita_config_tests_header
suite = TestLoader().loadTestsFromTestCase(QiitaConfig)
TextTestRunner(stream=stdout, verbosity=1).run(suite)
Expand Down