Skip to content

Commit f3874d5

Browse files
committed
use more helpful nose.assert_* functions
1 parent f73f1e0 commit f3874d5

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

tests/test_utils.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
from vipaccess.provision import *
2525

26+
from nose.tools import assert_equal, assert_true, assert_false, assert_is_none, assert_is_not_none
27+
2628

2729
def test_generate_request():
2830
expected = '<?xml version="1.0" encoding="UTF-8" ?>\n<GetSharedSecret Id="1412030064" Version="2.0"\n xmlns="http://www.verisign.com/2006/08/vipservice"\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n <TokenModel>SYMC</TokenModel>\n <ActivationCode></ActivationCode>\n <OtpAlgorithm type="HMAC-SHA1-TRUNC-6DIGITS"/>\n <SharedSecretDeliveryMethod>HTTPS</SharedSecretDeliveryMethod>\n <DeviceId>\n <Manufacturer>Apple Inc.</Manufacturer>\n <SerialNo>7QJR44Y54LK3</SerialNo>\n <Model>MacBookPro10,1</Model>\n </DeviceId>\n <Extension extVersion="auth" xsi:type="vip:ProvisionInfoType"\n xmlns:vip="http://www.verisign.com/2006/08/vipservice">\n <AppHandle>iMac010200</AppHandle>\n <ClientIDType>BOARDID</ClientIDType>\n <ClientID>Mac-3E36319D3EA483BD</ClientID>\n <DistChannel>Symantec</DistChannel>\n <ClientInfo>\n <os>MacBookPro10,1</os>\n <platform>iMac</platform>\n </ClientInfo>\n <ClientTimestamp>1412030064</ClientTimestamp>\n <Data>Y95GpBio35otwd2H/4TjrukR0AnG7VR/KJ7qxz5Y370=</Data>\n </Extension>\n</GetSharedSecret>'
@@ -42,7 +44,7 @@ def test_generate_request():
4244
'os': 'MacBookPro10,1',
4345
}
4446
request = generate_request(**params)
45-
assert request == expected
47+
assert_equal(expected, request)
4648

4749
def test_get_token_from_response():
4850
test_response = b'<?xml version="1.0" encoding="UTF-8"?>\n<GetSharedSecretResponse RequestId="1412030064" Version="2.0" xmlns="http://www.verisign.com/2006/08/vipservice">\n <Status>\n <ReasonCode>0000</ReasonCode>\n <StatusMessage>Success</StatusMessage>\n </Status>\n <SharedSecretDeliveryMethod>HTTPS</SharedSecretDeliveryMethod>\n <SecretContainer Version="1.0">\n <EncryptionMethod>\n <PBESalt>u5lgf1Ek8WA0iiIwVkjy26j6pfk=</PBESalt>\n <PBEIterationCount>50</PBEIterationCount>\n <IV>Fsg1KafmAX80gUEDADijHw==</IV>\n </EncryptionMethod>\n <Device>\n <Secret type="HOTP" Id="SYMC26070843">\n <Issuer>OU = ID Protection Center, O = VeriSign, Inc.</Issuer>\n <Usage otp="true">\n <AI type="HMAC-SHA1-TRUNC-6DIGITS"/>\n <TimeStep>30</TimeStep>\n <Time>0</Time>\n <ClockDrift>4</ClockDrift>\n </Usage>\n <FriendlyName>OU = ID Protection Center, O = VeriSign, Inc.</FriendlyName>\n <Data>\n <Cipher>ILBweOCEOoMBLJARzoeUIlu0+5m6b3khZljd5dozARk=</Cipher>\n <Digest algorithm="HMAC-SHA1">MoaidW7XDzeTZJqhfRQCZEieARM=</Digest>\n </Data>\n <Expiry>2017-09-25T23:36:22.056Z</Expiry>\n </Secret>\n </Device>\n </SecretContainer>\n <UTCTimestamp>1412030065</UTCTimestamp>\n</GetSharedSecretResponse>'
@@ -60,15 +62,15 @@ def test_get_token_from_response():
6062
'counter': None,
6163
}
6264
token = get_token_from_response(test_response)
63-
assert token.pop('timeskew', None) is not None
64-
assert token == expected_token
65+
assert_is_not_none(token.pop('timeskew', None))
66+
assert_equal(expected_token, token)
6567

6668
def test_decrypt_key():
6769
test_iv = b'\x16\xc85)\xa7\xe6\x01\x7f4\x81A\x03\x008\xa3\x1f'
6870
test_cipher = b' \xb0px\xe0\x84:\x83\x01,\x90\x11\xce\x87\x94"[\xb4\xfb\x99\xbaoy!fX\xdd\xe5\xda3\x01\x19'
6971
expected_key = b'ZqeD\xd9wg]"\x12\x1f7\xc7v6"\xf0\x13\\i'
7072
decrypted_key = decrypt_key(test_iv, test_cipher)
71-
assert decrypted_key == expected_key
73+
assert_equal(expected_key, decrypted_key)
7274

7375
def test_generate_totp_uri():
7476
test_token = {
@@ -88,11 +90,11 @@ def test_generate_totp_uri():
8890
test_secret = b'ZqeD\xd9wg]"\x12\x1f7\xc7v6"\xf0\x13\\i'
8991
expected_uri = urlparse.urlparse('otpauth://totp/VIP%20Access:SYMC26070843?secret=LJYWKRGZO5TV2IQSD434O5RWELYBGXDJ&issuer=Symantec&digits=6&algorithm=SHA1&period=30&image=https://vip.symantec.com/favicon.ico')
9092
generated_uri = urlparse.urlparse(generate_otp_uri(test_token, test_secret))
91-
assert generated_uri.scheme == expected_uri.scheme
92-
assert generated_uri.netloc == expected_uri.netloc
93-
assert generated_uri.path == expected_uri.path
94-
assert urlparse.parse_qs(generated_uri.params) == urlparse.parse_qs(expected_uri.params)
95-
assert urlparse.parse_qs(generated_uri.query) == urlparse.parse_qs(expected_uri.query)
93+
assert_equal(expected_uri.scheme, generated_uri.scheme)
94+
assert_equal(expected_uri.netloc, generated_uri.netloc)
95+
assert_equal(expected_uri.path, generated_uri.path)
96+
assert_equal(urlparse.parse_qs(expected_uri.params), urlparse.parse_qs(generated_uri.params))
97+
assert_equal(urlparse.parse_qs(expected_uri.query), urlparse.parse_qs(generated_uri.query))
9698

9799
def test_generate_hotp_uri():
98100
test_token = {
@@ -112,21 +114,21 @@ def test_generate_hotp_uri():
112114
test_secret = b'\x9a\x13\xcd2!\xad\xbd\x97R\xfcEE\xb6\x92e\xb4\x14\xb0\xfem'
113115
expected_uri = urlparse.urlparse('otpauth://hotp/VIP%20Access:UBHE57586348?digits=6&algorithm=SHA1&counter=1&issuer=Symantec&secret=TIJ42MRBVW6ZOUX4IVC3NETFWQKLB7TN&image=https://vip.symantec.com/favicon.ico')
114116
generated_uri = urlparse.urlparse(generate_otp_uri(test_token, test_secret))
115-
assert generated_uri.scheme == expected_uri.scheme
116-
assert generated_uri.netloc == expected_uri.netloc
117-
assert generated_uri.path == expected_uri.path
118-
assert urlparse.parse_qs(generated_uri.params) == urlparse.parse_qs(expected_uri.params)
119-
assert urlparse.parse_qs(generated_uri.query) == urlparse.parse_qs(expected_uri.query)
117+
assert_equal(expected_uri.scheme, generated_uri.scheme)
118+
assert_equal(expected_uri.netloc, generated_uri.netloc)
119+
assert_equal(expected_uri.path, generated_uri.path)
120+
assert_equal(urlparse.parse_qs(expected_uri.params), urlparse.parse_qs(generated_uri.params))
121+
assert_equal(urlparse.parse_qs(expected_uri.query), urlparse.parse_qs(generated_uri.query))
120122

121123
def provision_valid_token(token_model, attr, not_attr):
122124
test_request = generate_request(token_model=token_model)
123125
test_response = requests.post(PROVISIONING_URL, data=test_request)
124126
test_otp_token = get_token_from_response(test_response.content)
125-
assert test_otp_token[attr] is not None
126-
assert test_otp_token[not_attr] is None
127+
assert_is_not_none(test_otp_token[attr])
128+
assert_is_none(test_otp_token[not_attr])
127129
assert test_otp_token['id'].startswith(token_model)
128130
test_token_secret = decrypt_key(test_otp_token['iv'], test_otp_token['cipher'])
129-
assert check_token(test_otp_token, test_token_secret)
131+
assert_true(check_token(test_otp_token, test_token_secret))
130132

131133
def test_check_token_models():
132134
for token_model in ('VSMT', 'VSST', 'SYMC', 'SYDC'):
@@ -137,4 +139,4 @@ def test_check_token_models():
137139
def test_check_token_detects_invalid_token():
138140
test_token = {'id': 'SYMC26070843', 'period': 30}
139141
test_token_secret = b'ZqeD\xd9wg]"\x12\x1f7\xc7v6"\xf0\x13\\i'
140-
assert not check_token(test_token, test_token_secret)
142+
assert_false(check_token(test_token, test_token_secret))

0 commit comments

Comments
 (0)