Skip to content
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

Add compute engine system tests #54

Merged
merged 2 commits into from
Oct 25, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/auth/compute_engine/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# This is used to ping the metadata server, it avoids the cost of a DNS
# lookup.
_METADATA_IP_ROOT = 'http://169.254.169.254'
_METADATA_FLAVOR_HEADER = 'metdata-flavor'
_METADATA_FLAVOR_HEADER = 'metadata-flavor'
_METADATA_FLAVOR_VALUE = 'Google'
_METADATA_HEADERS = {_METADATA_FLAVOR_HEADER: _METADATA_FLAVOR_VALUE}

Expand Down
3 changes: 1 addition & 2 deletions google/auth/compute_engine/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

"""

from google.auth import _helpers
from google.auth import credentials
from google.auth import exceptions
from google.auth.compute_engine import _metadata
Expand Down Expand Up @@ -71,7 +70,7 @@ def _retrieve_info(self, request):
service_account=self._service_account_email)

self._service_account_email = info['email']
self._scopes = _helpers.string_to_scopes(info['scopes'])
self._scopes = info['scopes']

This comment was marked as spam.

This comment was marked as spam.


def refresh(self, request):
"""Refresh the access token and scopes.
Expand Down
37 changes: 37 additions & 0 deletions system_tests/test_compute_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from google.auth import _helpers
from google.auth import compute_engine
from google.auth.compute_engine import _metadata
import pytest

This comment was marked as spam.

This comment was marked as spam.



@pytest.fixture(autouse=True)
def check_gce_environment(request):
if not _metadata.ping(request):
pytest.skip('Compute Engine metadata service is not available.')


This comment was marked as spam.

This comment was marked as spam.

def test_refresh(request, token_info):

This comment was marked as spam.

This comment was marked as spam.

credentials = compute_engine.Credentials()

credentials.refresh(request)

assert credentials.token is not None
assert credentials._service_account_email is not None

This comment was marked as spam.

This comment was marked as spam.


info = token_info(credentials.token)
info_scopes = _helpers.string_to_scopes(info['scope'])

This comment was marked as spam.

assert set(info_scopes) == set(credentials.scopes)
8 changes: 5 additions & 3 deletions system_tests/test_service_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from google.auth import _helpers
from google.auth import exceptions
from google.oauth2 import service_account
import pytest
Expand All @@ -38,6 +39,7 @@ def test_refresh_success(request, credentials, token_info):
info = token_info(credentials.token)

assert info['email'] == credentials._service_account_email
assert info['scope'] == (
'https://www.googleapis.com/auth/userinfo.email '
'https://www.googleapis.com/auth/userinfo.profile')
info_scopes = _helpers.string_to_scopes(info['scope'])

This comment was marked as spam.

assert set(info_scopes) == set([
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'])
2 changes: 1 addition & 1 deletion tests/compute_engine/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_refresh_success(self, get_mock, now_mock):
get_mock.side_effect = [{
# First request is for sevice account info.
'email': 'service-account@example.com',
'scopes': 'one two'
'scopes': ['one', 'two']
}, {
# Second request is for the token.
'access_token': 'token',
Expand Down