-
Couldn't load subscription status.
- Fork 79
Plugins oauth2 #1584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugins oauth2 #1584
Changes from 10 commits
cb99e04
e8169f3
1004130
2aa5876
f963137
100b354
be34c7c
3a305d8
b9d6931
12dab96
dbccfca
1c4ea5b
e474219
1b2bdbc
c6eebfb
64e0713
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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]) | ||
| TRN.execute() | ||
|
|
||
| print "Please, add these values to your target gene plugin configuration file:" | ||
| print "CLIENT_ID = %s" % client_id | ||
| print "CLIENT_SECRET = %s" % client_secret |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = [] | ||
|
|
||
|
|
@@ -51,6 +58,11 @@ def test_get_artifact_information(self): | |
| httpretty.GET, | ||
| "https://test_server.com/qiita_db/artifacts/1/type/", | ||
| body='{"type": "FASTQ", "success": true, "error": ""}') | ||
| httpretty.register_uri( | ||
| httpretty.POST, | ||
| "https://test_server.com/qiita_db/authenticate/", | ||
| body='{"access_token": "token", "token_type": "Bearer", ' | ||
| '"expires_in": "3600"}') | ||
|
|
||
| obs_fps, obs_mf, obs_at = get_artifact_information(self.qclient, 1) | ||
|
|
||
|
|
@@ -67,6 +79,11 @@ def test_get_artifact_error(self): | |
| httpretty.GET, | ||
| "https://test_server.com/qiita_db/artifacts/1/filepaths/", | ||
| body='{"filepaths": '', "success": false, "error": "some error"}') | ||
| httpretty.register_uri( | ||
|
||
| httpretty.POST, | ||
| "https://test_server.com/qiita_db/authenticate/", | ||
| body='{"access_token": "token", "token_type": "Bearer", ' | ||
| '"expires_in": "3600"}') | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| get_artifact_information(self.qclient, 1) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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') | ||
|
|
@@ -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( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated from setUp There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
|
|
@@ -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 | ||
| VQQKEwRVQ1NEMRIwEA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3erg6wG95q5OiGNO1WYSw2 | ||
| -----END CERTIFICATE-----""" | ||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated from setUp