Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 37dbaf5

Browse files
committed
Test with an IAM authenticated client
1 parent 541ed50 commit 37dbaf5

File tree

6 files changed

+119
-36
lines changed

6 files changed

+119
-36
lines changed

Jenkinsfile

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,33 @@ def test_python(pythonVersion)
2626
}
2727
}
2828

29+
def test_python_iam(pythonVersion)
30+
{
31+
node {
32+
// Unstash the source on this node
33+
unstash name: 'source'
34+
// Set up the environment and test
35+
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'iam-testy023', usernameVariable: 'DB_USER', passwordVariable: 'IAM_API_KEY']]) {
36+
try {
37+
sh """ virtualenv tmp -p /usr/local/lib/python${pythonVersion}/bin/${pythonVersion.startsWith('3') ? "python3" : "python"}
38+
. ./tmp/bin/activate
39+
echo \$DB_USER
40+
export RUN_CLOUDANT_TESTS=1
41+
export CLOUDANT_ACCOUNT=\$DB_USER
42+
# Temporarily disable the _db_updates tests pending resolution of case 71610
43+
export SKIP_DB_UPDATES=1
44+
pip install -r requirements.txt
45+
pip install -r test-requirements.txt
46+
pylint ./src/cloudant
47+
nosetests -w ./tests/unit --with-xunit"""
48+
} finally {
49+
// Load the test results
50+
junit 'nosetests.xml'
51+
}
52+
}
53+
}
54+
}
55+
2956
// Start of build
3057
stage('Checkout'){
3158
// Checkout and stash the source
@@ -38,6 +65,8 @@ stage('Test'){
3865
// Run tests in parallel for multiple python versions
3966
parallel(
4067
Python2: {test_python('2.7.12')},
41-
Python3: {test_python('3.5.2')}
68+
Python3: {test_python('3.5.2')},
69+
'Python2-IAM': {test_python_iam('2.7.12')},
70+
'Python3-IAM': {test_python_iam('3.5.2')}
4271
)
4372
}

tests/unit/auth_renewal_tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from cloudant.client_session import CookieSession
2727

28-
from .unit_t_db_base import UnitTestDbBase
28+
from .unit_t_db_base import skip_for_iam, UnitTestDbBase
2929

3030
@unittest.skipIf(os.environ.get('ADMIN_PARTY') == 'true', 'Skipping - Admin Party mode')
3131
class AuthRenewalTests(UnitTestDbBase):
@@ -44,7 +44,8 @@ def tearDown(self):
4444
Override UnitTestDbBase.tearDown() with no tear down
4545
"""
4646
pass
47-
47+
48+
@skip_for_iam
4849
def test_client_db_doc_stack_success(self):
4950
"""
5051
Ensure that auto renewal of cookie auth happens as expected and applies

tests/unit/client_tests.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from cloudant.error import CloudantArgumentError, CloudantClientException
4040
from cloudant.feed import Feed, InfiniteFeed
4141

42-
from .unit_t_db_base import UnitTestDbBase
42+
from .unit_t_db_base import skip_for_iam, UnitTestDbBase
4343
from .. import bytes_, str_
4444

4545
class CloudantClientExceptionTests(unittest.TestCase):
@@ -164,6 +164,7 @@ def test_multiple_connect(self):
164164
self.client.disconnect()
165165
self.assertIsNone(self.client.r_session)
166166

167+
@skip_for_iam
167168
def test_auto_renew_enabled(self):
168169
"""
169170
Test that CookieSession is used when auto_renew is enabled.
@@ -178,6 +179,7 @@ def test_auto_renew_enabled(self):
178179
finally:
179180
self.client.disconnect()
180181

182+
@skip_for_iam
181183
def test_auto_renew_enabled_with_auto_connect(self):
182184
"""
183185
Test that CookieSession is used when auto_renew is enabled along with
@@ -192,6 +194,7 @@ def test_auto_renew_enabled_with_auto_connect(self):
192194
finally:
193195
self.client.disconnect()
194196

197+
@skip_for_iam
195198
def test_session(self):
196199
"""
197200
Test getting session information.
@@ -207,6 +210,7 @@ def test_session(self):
207210
finally:
208211
self.client.disconnect()
209212

213+
@skip_for_iam
210214
def test_session_cookie(self):
211215
"""
212216
Test getting the session cookie.
@@ -315,6 +319,7 @@ def test_change_credentials_basic(self, m_req):
315319
)
316320
self.assertEquals(all_dbs, ['animaldb'])
317321

322+
@skip_for_iam
318323
def test_basic_auth_str(self):
319324
"""
320325
Test getting the basic authentication string.
@@ -589,6 +594,7 @@ class CloudantClientTests(UnitTestDbBase):
589594
Cloudant specific client unit tests
590595
"""
591596

597+
@skip_for_iam
592598
def test_cloudant_session_login(self):
593599
"""
594600
Test that the Cloudant client session successfully authenticates.
@@ -601,6 +607,7 @@ def test_cloudant_session_login(self):
601607
self.client.session_login()
602608
self.assertNotEqual(self.client.session_cookie(), old_cookie)
603609

610+
@skip_for_iam
604611
def test_cloudant_session_login_with_new_credentials(self):
605612
"""
606613
Test that the Cloudant client session fails to authenticate when
@@ -613,6 +620,7 @@ def test_cloudant_session_login_with_new_credentials(self):
613620

614621
self.assertTrue(str(cm.exception).find('Name or password is incorrect'))
615622

623+
@skip_for_iam
616624
def test_cloudant_context_helper(self):
617625
"""
618626
Test that the cloudant context helper works as expected.
@@ -624,6 +632,7 @@ def test_cloudant_context_helper(self):
624632
except Exception as err:
625633
self.fail('Exception {0} was raised.'.format(str(err)))
626634

635+
@skip_for_iam
627636
def test_cloudant_bluemix_context_helper(self):
628637
"""
629638
Test that the cloudant_bluemix context helper works as expected.
@@ -688,6 +697,7 @@ def test_constructor_with_account(self):
688697
'https://{0}.cloudant.com'.format(self.account)
689698
)
690699

700+
@skip_for_iam
691701
def test_bluemix_constructor(self):
692702
"""
693703
Test instantiating a client object using a VCAP_SERVICES environment
@@ -720,6 +730,7 @@ def test_bluemix_constructor(self):
720730
finally:
721731
c.disconnect()
722732

733+
@skip_for_iam
723734
def test_bluemix_constructor_specify_instance_name(self):
724735
"""
725736
Test instantiating a client object using a VCAP_SERVICES environment
@@ -752,6 +763,7 @@ def test_bluemix_constructor_specify_instance_name(self):
752763
finally:
753764
c.disconnect()
754765

766+
@skip_for_iam
755767
def test_bluemix_constructor_with_multiple_services(self):
756768
"""
757769
Test instantiating a client object using a VCAP_SERVICES environment
@@ -819,6 +831,7 @@ def test_connect_headers(self):
819831
finally:
820832
self.client.disconnect()
821833

834+
@skip_for_iam
822835
def test_connect_timeout(self):
823836
"""
824837
Test that a connect timeout occurs when instantiating
@@ -845,6 +858,7 @@ def test_db_updates_infinite_feed_call(self):
845858
finally:
846859
self.client.disconnect()
847860

861+
@skip_for_iam
848862
def test_billing_data(self):
849863
"""
850864
Test the retrieval of billing data
@@ -939,6 +953,7 @@ def test_set_year_with_invalid_month_for_billing_data(self):
939953
finally:
940954
self.client.disconnect()
941955

956+
@skip_for_iam
942957
def test_volume_usage_data(self):
943958
"""
944959
Test the retrieval of volume usage data
@@ -1030,6 +1045,7 @@ def test_set_year_with_invalid_month_for_volume_usage_data(self):
10301045
finally:
10311046
self.client.disconnect()
10321047

1048+
@skip_for_iam
10331049
def test_requests_usage_data(self):
10341050
"""
10351051
Test the retrieval of requests usage data
@@ -1121,6 +1137,7 @@ def test_set_year_with_invalid_month_for_requests_usage_data(self):
11211137
finally:
11221138
self.client.disconnect()
11231139

1140+
@skip_for_iam
11241141
def test_shared_databases(self):
11251142
"""
11261143
Test the retrieval of shared database list
@@ -1131,6 +1148,7 @@ def test_shared_databases(self):
11311148
finally:
11321149
self.client.disconnect()
11331150

1151+
@skip_for_iam
11341152
def test_generate_api_key(self):
11351153
"""
11361154
Test the generation of an API key for this client account
@@ -1144,6 +1162,7 @@ def test_generate_api_key(self):
11441162
finally:
11451163
self.client.disconnect()
11461164

1165+
@skip_for_iam
11471166
def test_cors_configuration(self):
11481167
"""
11491168
Test the retrieval of the current CORS configuration for this client
@@ -1157,6 +1176,7 @@ def test_cors_configuration(self):
11571176
finally:
11581177
self.client.disconnect()
11591178

1179+
@skip_for_iam
11601180
def test_cors_origins(self):
11611181
"""
11621182
Test the retrieval of the CORS origins list
@@ -1168,6 +1188,7 @@ def test_cors_origins(self):
11681188
finally:
11691189
self.client.disconnect()
11701190

1191+
@skip_for_iam
11711192
def test_disable_cors(self):
11721193
"""
11731194
Test disabling CORS (assuming CORS is enabled)
@@ -1188,6 +1209,7 @@ def test_disable_cors(self):
11881209
finally:
11891210
self.client.disconnect()
11901211

1212+
@skip_for_iam
11911213
def test_update_cors_configuration(self):
11921214
"""
11931215
Test updating CORS configuration

tests/unit/database_tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from cloudant.feed import Feed, InfiniteFeed
3939
from tests.unit._test_util import LONG_NUMBER
4040

41-
from .unit_t_db_base import UnitTestDbBase
41+
from .unit_t_db_base import skip_for_iam, UnitTestDbBase
4242
from .. import unicode_
4343

4444
class CloudantDatabaseExceptionTests(unittest.TestCase):
@@ -151,6 +151,7 @@ def test_retrieve_db_url(self):
151151
'/'.join((self.client.server_url, self.test_dbname))
152152
)
153153

154+
@skip_for_iam
154155
def test_retrieve_creds(self):
155156
"""
156157
Test retrieving client credentials. The client credentials are None if
@@ -370,6 +371,7 @@ def test_retrieve_design_document(self):
370371
ddoc = self.db.get_design_document('_design/ddoc01')
371372
self.assertEqual(ddoc, local_ddoc)
372373

374+
@skip_for_iam
373375
def test_get_security_document(self):
374376
"""
375377
Test retrieving the database security document
@@ -995,6 +997,7 @@ def test_unshare_database_uses_custom_encoder(self):
995997
with self.assertRaises(TypeError):
996998
database.unshare_database(share)
997999

1000+
@skip_for_iam
9981001
def test_security_document(self):
9991002
"""
10001003
Test the retrieval of the security document.
@@ -1004,6 +1007,7 @@ def test_security_document(self):
10041007
expected = {'cloudant': {share: ['_reader']}}
10051008
self.assertDictEqual(self.db.security_document(), expected)
10061009

1010+
@skip_for_iam
10071011
def test_share_database_default_permissions(self):
10081012
"""
10091013
Test the sharing of a database applying default permissions.
@@ -1014,6 +1018,7 @@ def test_share_database_default_permissions(self):
10141018
expected = {'cloudant': {share: ['_reader']}}
10151019
self.assertDictEqual(self.db.security_document(), expected)
10161020

1021+
@skip_for_iam
10171022
def test_share_database(self):
10181023
"""
10191024
Test the sharing of a database.
@@ -1024,6 +1029,7 @@ def test_share_database(self):
10241029
expected = {'cloudant': {share: ['_writer']}}
10251030
self.assertDictEqual(self.db.security_document(), expected)
10261031

1032+
@skip_for_iam
10271033
def test_share_database_with_redundant_role_entries(self):
10281034
"""
10291035
Test the sharing of a database works when the list of roles contains
@@ -1066,6 +1072,7 @@ def test_share_database_empty_role_list(self):
10661072
'\'_db_updates\', \'_design\', \'_shards\', \'_security\']'
10671073
)
10681074

1075+
@skip_for_iam
10691076
def test_unshare_database(self):
10701077
"""
10711078
Test the un-sharing of a database from a specified user.

tests/unit/replicator_tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from cloudant.document import Document
3535
from cloudant.error import CloudantReplicatorException, CloudantClientException
3636

37-
from .unit_t_db_base import UnitTestDbBase
37+
from .unit_t_db_base import skip_for_iam, UnitTestDbBase
3838
from .. import unicode_
3939

4040
class CloudantReplicatorExceptionTests(unittest.TestCase):
@@ -157,6 +157,7 @@ def test_replication_with_generated_id(self):
157157
clone = Replicator(self.client)
158158
clone.create_replication(self.db, self.target_db)
159159

160+
@skip_for_iam
160161
@flaky(max_runs=3)
161162
def test_create_replication(self):
162163
"""
@@ -300,6 +301,7 @@ def test_list_replications(self):
300301
match = [repl_id for repl_id in all_repl_ids if repl_id in repl_ids]
301302
self.assertEqual(set(repl_ids), set(match))
302303

304+
@skip_for_iam
303305
def test_retrieve_replication_state(self):
304306
"""
305307
Test that the replication state can be retrieved for a replication
@@ -341,6 +343,7 @@ def test_retrieve_replication_state_using_invalid_id(self):
341343
)
342344
self.assertIsNone(repl_state)
343345

346+
@skip_for_iam
344347
def test_stop_replication(self):
345348
"""
346349
Test that a replication can be stopped.
@@ -376,6 +379,7 @@ def test_stop_replication_using_invalid_id(self):
376379
'Replication with id {} not found.'.format(repl_id)
377380
)
378381

382+
@skip_for_iam
379383
def test_follow_replication(self):
380384
"""
381385
Test that follow_replication(...) properly iterates updated

0 commit comments

Comments
 (0)