Skip to content

Commit 7ffbe1b

Browse files
sfc-gh-stakedaankit-bhatnagar167
authored andcommitted
SNOW-115762: skip key pair auth tests against prod.
1 parent 9b4dcfa commit 7ffbe1b

File tree

4 files changed

+35
-57
lines changed

4 files changed

+35
-57
lines changed

test/conftest.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
'port': '443',
5757
}
5858

59-
IS_PUBLIC_CI = os.getenv('TRAVIS') == 'true' or os.getenv('APPVEYOR') == 'True'
60-
6159

6260
def help():
6361
print("""Connection parameter must be specified in parameters.py,
@@ -72,6 +70,18 @@ def help():
7270
""")
7371

7472

73+
@pytest.fixture(scope='session')
74+
def is_public_test():
75+
return is_public_testaccount()
76+
77+
78+
def is_public_testaccount():
79+
db_parameters = get_db_parameters()
80+
return os.getenv('TRAVIS') == 'true' or \
81+
os.getenv('APPVEYOR') == 'True' or \
82+
db_parameters.get('account').startswith('sfctest0')
83+
84+
7585
@pytest.fixture(scope='session')
7686
def db_parameters():
7787
return get_db_parameters()
@@ -305,7 +315,7 @@ def negative_db(**kwargs):
305315
if not kwargs.get(u'converter_class'):
306316
kwargs[u'converter_class'] = DefaultConverterClass()
307317
cnx = create_connection(**kwargs)
308-
if not IS_PUBLIC_CI:
318+
if not is_public_testaccount():
309319
cnx.cursor().execute("alter session set SUPPRESS_INCIDENT_DUMPS=true")
310320
try:
311321
yield cnx
@@ -344,5 +354,5 @@ def test_files():
344354

345355
def pytest_runtest_setup(item):
346356
for _ in item.iter_markers(name="internal"):
347-
if IS_PUBLIC_CI:
357+
if is_public_testaccount():
348358
pytest.skip("cannot run on public CI")

test/test_connection.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -414,20 +414,6 @@ def test_invalid_account_timeout():
414414
)
415415

416416

417-
@pytest.mark.timeout(15)
418-
def test_invalid_port(db_parameters):
419-
with pytest.raises(OperationalError):
420-
snowflake.connector.connect(
421-
protocol='http',
422-
account='testaccount',
423-
user=db_parameters['user'],
424-
password=db_parameters['password'],
425-
host=db_parameters['host'],
426-
port=12345,
427-
login_timeout=5,
428-
)
429-
430-
431417
@pytest.mark.timeout(15)
432418
def test_invalid_proxy(db_parameters):
433419
with pytest.raises(OperationalError):

test/test_key_pair_authentication.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# Copyright (c) 2012-2019 Snowflake Computing Inc. All right reserved.
55
#
66

7-
import os
8-
97
import pytest
108
from cryptography.hazmat.backends import default_backend
119
from cryptography.hazmat.primitives import serialization
@@ -14,16 +12,11 @@
1412

1513
import snowflake.connector
1614

17-
NO_ACCOUNTADMIN_PRIV = os.getenv('TRAVIS') == 'true' or \
18-
os.getenv('APPVEYOR') == 'True' or \
19-
os.getenv('sf_account') == 'testaccount5'
2015

16+
def test_different_key_length(is_public_test, request, conn_cnx, db_parameters):
17+
if is_public_test:
18+
pytest.skip('This test requires ACCOUNTADMIN privilege to set the public key')
2119

22-
@pytest.mark.skipif(
23-
NO_ACCOUNTADMIN_PRIV,
24-
reason="Change user's public key requires accountadmin privilege"
25-
)
26-
def test_different_key_length(request, conn_cnx, db_parameters):
2720
db_config = {
2821
'protocol': db_parameters['protocol'],
2922
'account': db_parameters['account'],
@@ -63,11 +56,10 @@ def fin():
6356
snowflake.connector.connect(**db_config)
6457

6558

66-
@pytest.mark.skipif(
67-
NO_ACCOUNTADMIN_PRIV,
68-
reason="Change user's public key requires accountadmin privilege"
69-
)
70-
def test_multiple_key_pair(request, conn_cnx, db_parameters):
59+
def test_multiple_key_pair(is_public_test, request, conn_cnx, db_parameters):
60+
if is_public_test:
61+
pytest.skip('This test requires ACCOUNTADMIN privilege to set the public key')
62+
7163
db_config = {
7264
'protocol': db_parameters['protocol'],
7365
'account': db_parameters['account'],

test/test_put_get_user_stage.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,24 @@
1212
import pytest
1313

1414

15-
@pytest.mark.skipif(
16-
'AWS_ACCESS_KEY_ID' not in os.environ,
17-
reason="Snowflake admin account is not accessible."
18-
)
1915
def test_put_get_small_data_via_user_stage(
20-
tmpdir, test_files, conn_cnx, db_parameters):
16+
is_public_test, tmpdir, test_files, conn_cnx, db_parameters):
2117
"""
2218
[s3] Put and Get Small Data via User Stage
2319
"""
20+
if is_public_test or 'AWS_ACCESS_KEY_ID' not in os.environ:
21+
pytest.skip('This test requires to change the internal parameter')
2422
_put_get_user_stage(tmpdir, test_files, conn_cnx, db_parameters,
2523
number_of_files=5, number_of_lines=10)
2624

2725

28-
@pytest.mark.skipif(
29-
'AWS_ACCESS_KEY_ID' not in os.environ,
30-
reason="Snowflake admin account is not accessible."
31-
)
32-
def test_put_get_large_data_via_user_stage(tmpdir, test_files, conn_cnx,
33-
db_parameters):
26+
def test_put_get_large_data_via_user_stage(
27+
is_public_test, tmpdir, test_files, conn_cnx, db_parameters):
3428
"""
3529
[s3] Put and Get Large Data via User Stage
3630
"""
31+
if is_public_test or 'AWS_ACCESS_KEY_ID' not in os.environ:
32+
pytest.skip('This test requires to change the internal parameter')
3733
_put_get_user_stage(tmpdir, test_files, conn_cnx, db_parameters,
3834
number_of_files=2,
3935
number_of_lines=200000)
@@ -142,17 +138,16 @@ def _put_get_user_stage(tmpdir, test_files, conn_cnx, db_parameters,
142138
name=db_parameters['name']))
143139

144140

145-
@pytest.mark.skipif(
146-
'AWS_ACCESS_KEY_ID' not in os.environ,
147-
reason="Snowflake admin account is not accessible."
148-
)
149-
def test_put_get_duplicated_data_user_stage(tmpdir, test_files, conn_cnx,
141+
def test_put_get_duplicated_data_user_stage(is_public_test, tmpdir, test_files, conn_cnx,
150142
db_parameters,
151143
number_of_files=5,
152144
number_of_lines=100):
153145
"""
154146
[s3] Put and Get Duplicated Data using User Stage
155147
"""
148+
if is_public_test or 'AWS_ACCESS_KEY_ID' not in os.environ:
149+
pytest.skip('This test requires to change the internal parameter')
150+
156151
logger = getLogger(__name__)
157152
assert 'AWS_ACCESS_KEY_ID' in os.environ, 'AWS_ACCESS_KEY_ID is missing'
158153
assert 'AWS_SECRET_ACCESS_KEY' in os.environ, \
@@ -302,17 +297,12 @@ def test_put_get_duplicated_data_user_stage(tmpdir, test_files, conn_cnx,
302297
name=db_parameters['name']))
303298

304299

305-
@pytest.mark.skipif(
306-
'AWS_ACCESS_KEY_ID' not in os.environ,
307-
reason="Snowflake admin account is not accessible."
308-
)
309-
def test_get_data_user_stage(tmpdir, conn_cnx, db_parameters):
300+
def test_get_data_user_stage(is_public_test, tmpdir, conn_cnx, db_parameters):
310301
"""
311302
SNOW-20927: get failed with 404 error
312303
"""
313-
assert 'AWS_ACCESS_KEY_ID' in os.environ, 'AWS_ACCESS_KEY_ID is missing'
314-
assert 'AWS_SECRET_ACCESS_KEY' in os.environ, \
315-
'AWS_SECRET_ACCESS_KEY is missing'
304+
if is_public_test or 'AWS_ACCESS_KEY_ID' not in os.environ:
305+
pytest.skip('This test requires to change the internal parameter')
316306

317307
default_s3bucket = os.getenv('SF_AWS_USER_BUCKET',
318308
"sfc-dev1-regression/{0}/reg".format(

0 commit comments

Comments
 (0)