Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Adding system tests to make sure token exchange works as expected. #153

Merged
merged 2 commits into from
May 1, 2015

Conversation

dhermes
Copy link
Contributor

@dhermes dhermes commented Mar 29, 2015

Fixes #127

@dhermes
Copy link
Contributor Author

dhermes commented Mar 29, 2015

/cc @nathanielmanistaatgoogle

@coveralls
Copy link

Coverage Status

Coverage remained the same at 64.8% when pulling f07e816 on dhermes:fix-127 into 26adb9a on google:master.

@nathanielmanistaatgoogle
Copy link
Contributor

I'm going to need some more hand-holding on this - please file an issue so that we can have separate conversations about (a) the particular problem that needs to be solved and (2) the particular solution being proposed for the problem.

Also let's look at breaking up the content of the pull request. A CONTRIBUTING.md file is a great idea but most of its content has nothing to do with the rest of this code - can we separate it out into its own contribution?

How necessary is it to use an unreleased version of https://github.com/jcgregorio/httplib2? Has anyone actually asked @jcgregorio when the next release will be, or to cut a new release that includes the fix?

@dhermes
Copy link
Contributor Author

dhermes commented Mar 30, 2015

RE: "How necessary is it to use an unreleased version of httplib2

By removing it

diff --git a/tox.ini b/tox.ini
index d55d91d..578e3b5 100644
--- a/tox.ini
+++ b/tox.ini
@@ -88,9 +88,5 @@ basepython =
 commands =
     {toxinidir}/scripts/run_system_tests.sh
 deps =
-    # Use a development checkout of httplib2 until a release is made
-    # incorporating https://github.com/jcgregorio/httplib2/pull/291
-    # and https://github.com/jcgregorio/httplib2/pull/296
-    -egit+https://github.com/jcgregorio/httplib2.git#egg=httplib2
     pycrypto==2.6
     pyopenssl==0.14

and running tox -e system-tests3 (notice the recreate below), oauth2client just doesn't work

$ tox -e system-tests3
GLOB sdist-make: .../oauth2client/setup.py
system-tests3 recreate: .../oauth2client/.tox/system-tests3
system-tests3 installdeps: pycrypto==2.6, pyopenssl==0.14
system-tests3 inst: .../oauth2client/.tox/dist/oauth2client-1.4.7.zip
system-tests3 runtests: PYTHONHASHSEED='3334734548'
system-tests3 runtests: commands[0] | .../oauth2client/scripts/run_system_tests.sh


# If we're on Travis, we need to set up the environment.
...
# Run the system tests for each tested package.
python scripts/run_system_tests.py
Traceback (most recent call last):
  File "scripts/run_system_tests.py", line 107, in <module>
    main()
  File "scripts/run_system_tests.py", line 101, in main
    run_json()
  File "scripts/run_system_tests.py", line 66, in run_json
    _check_user_info(credentials, client_credentials['client_email'])
  File "scripts/run_system_tests.py", line 44, in _check_user_info
    response, content = http.request(USER_INFO)
  File ".../oauth2client/.tox/system-tests3/lib/python3.4/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File ".../oauth2client/.tox/system-tests3/lib/python3.4/site-packages/oauth2client/client.py", line 556, in new_request
    redirections, connection_type)
  File ".../oauth2client/.tox/system-tests3/lib/python3.4/site-packages/httplib2/__init__.py", line 1139, in request
    headers = self._normalize_headers(headers)
  File ".../oauth2client/.tox/system-tests3/lib/python3.4/site-packages/httplib2/__init__.py", line 1107, in _normalize_headers
    return _normalize_headers(headers)
  File ".../oauth2client/.tox/system-tests3/lib/python3.4/site-packages/httplib2/__init__.py", line 195, in _normalize_headers
    return dict([ (key.lower(), NORMALIZE_SPACE.sub(value, ' ').strip())  for (key, value) in headers.items()])
  File ".../oauth2client/.tox/system-tests3/lib/python3.4/site-packages/httplib2/__init__.py", line 195, in <listcomp>
    return dict([ (key.lower(), NORMALIZE_SPACE.sub(value, ' ').strip())  for (key, value) in headers.items()])
TypeError: sequence item 0: expected str instance, bytes found
ERROR: InvocationError: '.../oauth2client/scripts/run_system_tests.sh'
___________________________________________________________________ summary ____________________________________________________________________
ERROR:   system-tests3: commands failed

I asked @jcgregorio last week about cutting a release and have yet to hear back.


I'll send a PR (#155) with the base of CONTRIBUTING.md without the system tests section and then can rebase this on top of it. (Done.)

The changes to tests/data/gcloud/application_default_credentials_authorized_user.json can also be peeled off (#156). (I wanted this to resemble an actual application_default_credentials.json file that the gcloud CLI would create, via this library.) (Done.)


Issue #127 already exists to cover (a), and I think it also covers (2). Let me know what you think about that.

@nathanielmanistaatgoogle
Copy link
Contributor

You're absolutely right that #127 is the relevant issue for this change; sorry to have let it slip out of my mind.

@dhermes
Copy link
Contributor Author

dhermes commented Mar 30, 2015

@nathanielmanistaatgoogle I have rebased on top of #155 and #156. I split this PR into two commits to make the barrier clear between the tests themselves and the Travis config.


The second commit is a dummy / stand-in and should not be accepted in it's current state. Remaining work to be done:

  1. Create a dedicated Cloud Console account for Travis system tests.
  2. Create a service account and download a JSON key.
  3. Download a P12 key for that account (or create a new one).
  4. Create a JSON key for user credentials (can be as simple as copying ~/.config/gcloud/application_default_credentials.json)
  5. Sign in with the travis CLI tool. (See reference)
  6. Define and export the following environment variables:
export OAUTH2CLIENT_TEST_JSON_KEY_PATH="tests/data/key.json"
export OAUTH2CLIENT_TEST_P12_KEY_PATH="tests/data/key.p12"
# Account from svc. account P12 key
export OAUTH2CLIENT_TEST_P12_KEY_EMAIL="foo@developer.gserviceaccount.com"
export OAUTH2CLIENT_TEST_USER_KEY_PATH="tests/data/user-key.json"
# Account from user JSON key
export OAUTH2CLIENT_TEST_USER_KEY_EMAIL="foo@gmail.com"
  1. Set the Travis environment variables:
travis env set OAUTH2CLIENT_TEST_JSON_KEY_PATH \
    "${OAUTH2CLIENT_TEST_JSON_KEY_PATH}" --repo "google/oauth2client"
travis env set OAUTH2CLIENT_TEST_P12_KEY_PATH \
    "${OAUTH2CLIENT_TEST_P12_KEY_PATH}" --repo "google/oauth2client"
travis env set OAUTH2CLIENT_TEST_P12_KEY_EMAIL \
    "${OAUTH2CLIENT_TEST_P12_KEY_EMAIL}" --repo "google/oauth2client"
travis env set OAUTH2CLIENT_TEST_USER_KEY_PATH \
    "${OAUTH2CLIENT_TEST_USER_KEY_PATH}" --repo "google/oauth2client"
travis env set OAUTH2CLIENT_TEST_USER_KEY_EMAIL \
    "${OAUTH2CLIENT_TEST_USER_KEY_EMAIL}" --repo "google/oauth2client"
  1. Encrypt the key files against Travis
travis encrypt-file tests/data/key.json --repo "google/oauth2client"
travis encrypt-file tests/data/key.p12 --repo "google/oauth2client"
travis encrypt-file tests/data/user-key.json --repo "google/oauth2client"

This will create the files key.json.enc, key.p12.enc and user-key.json.enc in the tests/data/ directory. These are the files that need to be committed. Make sure to take note of the key printed in the travis output, e.g. $encrypted_0a6446eb3ae3_key. This value will be used in scripts/run_system_tests.sh to decrypt.
9. Log out of Travis (if you want):

travis logout

@coveralls
Copy link

Coverage Status

Coverage remained the same at 64.8% when pulling 3e5e1e7 on dhermes:fix-127 into 0a6241c on google:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 64.8% when pulling 3e5e1e7 on dhermes:fix-127 into 0a6241c on google:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 64.8% when pulling e19adfb on dhermes:fix-127 into 0a6241c on google:master.

@dhermes
Copy link
Contributor Author

dhermes commented Apr 2, 2015

@nathanielmanistaatgoogle Any blockers here?

- Updates CONTRIBUTING.md to explain how to set-up and run these tests.
- Requires a version of httplib2 that has not been released on PyPI
  yet in order to work on Python 3.
- Simply creates 3 different token types (JSON key for svc. acct.,
  P12 key for svc. acct., JSON key for user acct.) and then authorizes
  an httplib2.Http object to hit the USERINFO API.
@dhermes
Copy link
Contributor Author

dhermes commented Apr 13, 2015

I just updated this PR to incorporate the new release of httplib2 (thanks to @jcgregorio!!). (I folded it into the first commit.)

This will also mark the first time this library works with Python 3.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 64.8% when pulling a676713 on dhermes:fix-127 into 0a6241c on google:master.

Adds files which have been encrypted by Travis and
decrypts those files in scripts/run_system_tests.sh using
a key and initialization vector (iv) provided by the Travis
environment for this project.
nathanielmanistaatgoogle added a commit that referenced this pull request May 1, 2015
@nathanielmanistaatgoogle nathanielmanistaatgoogle merged commit 80bef44 into googleapis:master May 1, 2015
@coveralls
Copy link

Coverage Status

Coverage remained the same at 65.01% when pulling b65f2e1 on dhermes:fix-127 into 0023acb on google:master.

@dhermes dhermes deleted the fix-127 branch May 3, 2015 21:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add regression / integration tests for merges to master
4 participants