コード例 #1
0
class TestApplicationDefault(object):

    @pytest.mark.parametrize('app_default', [testutils.resource_filename('service_account.json')],
                             indirect=True)
    def test_init(self, app_default):
        del app_default
        credential = credentials.ApplicationDefault()
        assert credential.project_id == 'mock-project-id'

        g_credential = credential.get_credential()
        assert isinstance(g_credential, google.auth.credentials.Credentials)
        assert g_credential.token is None
        check_scopes(g_credential)

        mock_response = {'access_token': 'mock_access_token', 'expires_in': 3600}
        credentials._request = testutils.MockRequest(200, json.dumps(mock_response))
        access_token = credential.get_access_token()
        assert access_token.access_token == 'mock_access_token'
        assert isinstance(access_token.expiry, datetime.datetime)

    @pytest.mark.parametrize('app_default', [testutils.resource_filename('non_existing.json')],
                             indirect=True)
    def test_nonexisting_path(self, app_default):
        del app_default
        # This does not yet throw because the credentials are lazily loaded.
        creds = credentials.ApplicationDefault()

        with pytest.raises(exceptions.DefaultCredentialsError):
            creds.get_credential()  # This now throws.
コード例 #2
0
def test_service_account_with_explicit_app():
    cred = credentials.Certificate(
        testutils.resource_filename('service_account.json'))
    app = firebase_admin.initialize_app(cred)
    client = firestore.client(app=app)
    assert client is not None
    assert client.project == 'mock-project-id'
コード例 #3
0
def test_project_id():
    cred = credentials.Certificate(
        testutils.resource_filename('service_account.json'))
    firebase_admin.initialize_app(cred, {'projectId': 'explicit-project-id'})
    client = firestore.client()
    assert client is not None
    assert client.project == 'explicit-project-id'
コード例 #4
0
ファイル: test_db.py プロジェクト: 7chat/e7chats_admin-python
def update_rules(app):
    with open(testutils.resource_filename('dinosaurs_index.json')) as rules_file:
        new_rules = json.load(rules_file)
    client = db.reference('', app)._client
    rules = client.body('get', '/.settings/rules.json', params='format=strict')
    existing = rules.get('rules')
    if existing != new_rules:
        rules['rules'] = new_rules
        client.request('put', '/.settings/rules.json', json=rules)
コード例 #5
0
ファイル: test_db.py プロジェクト: nlbrown2/RPi-Lights-Server
def update_rules():
    with open(testutils.resource_filename('dinosaurs_index.json')) as rules_file:
        new_rules = json.load(rules_file)
    client = db.reference()._client
    rules = client.request('get', '/.settings/rules.json')
    existing = rules.get('rules', dict()).get('_adminsdk')
    if existing != new_rules:
        rules['rules']['_adminsdk'] = new_rules
        client.request('put', '/.settings/rules.json', json=rules)
コード例 #6
0
def set_config_env(config_json):
    config_old = os.environ.get(CONFIG_JSON)
    if config_json is not None:
        if not config_json or config_json.startswith('{'):
            os.environ[CONFIG_JSON] = config_json
        else:
            os.environ[CONFIG_JSON] = testutils.resource_filename(config_json)
    elif os.environ.get(CONFIG_JSON) is not None:
        del os.environ[CONFIG_JSON]
    return config_old
コード例 #7
0
class TestApplicationDefault(object):

    @pytest.mark.parametrize('app_default', [testutils.resource_filename('service_account.json')],
                             indirect=True)
    def test_init(self, app_default): # pylint: disable=unused-argument
        credential = credentials.ApplicationDefault()
        assert credential.project_id == 'mock-project-id'

        g_credential = credential.get_credential()
        assert isinstance(g_credential, google.auth.credentials.Credentials)
        assert g_credential.token is None
        check_scopes(g_credential)

        mock_response = {'access_token': 'mock_access_token', 'expires_in': 3600}
        credentials._request = testutils.MockRequest(200, json.dumps(mock_response))
        access_token = credential.get_access_token()
        assert access_token.access_token == 'mock_access_token'
        assert isinstance(access_token.expiry, datetime.datetime)

    @pytest.mark.parametrize('app_default', [testutils.resource_filename('non_existing.json')],
                             indirect=True)
    def test_nonexisting_path(self, app_default): # pylint: disable=unused-argument
        with pytest.raises(IOError):
            credentials.ApplicationDefault()
コード例 #8
0
def firebase_model(request):
    args = request.param
    tflite_format = None
    file_name = args.get('file_name')
    if file_name:
        file_path = testutils.resource_filename(file_name)
        source = ml.TFLiteGCSModelSource.from_tflite_model_file(file_path)
        tflite_format = ml.TFLiteFormat(model_source=source)

    ml_model = ml.Model(display_name=args.get('display_name'),
                        tags=args.get('tags'),
                        model_format=tflite_format)
    model = ml.create_model(model=ml_model)
    yield model
    _clean_up_model(model)
コード例 #9
0
    def test_init_from_file(self):
        credential = credentials.Certificate(
            testutils.resource_filename('service_account.json'))
        assert credential.project_id == 'mock-project-id'
        assert credential.service_account_email == '*****@*****.**'
        assert isinstance(credential.signer, crypt.Signer)

        g_credential = credential.get_credential()
        assert isinstance(g_credential, service_account.Credentials)
        assert g_credential.token is None
        check_scopes(g_credential)

        mock_response = {'access_token': 'mock_access_token', 'expires_in': 3600}
        credentials._request = testutils.MockRequest(200, json.dumps(mock_response))
        access_token = credential.get_access_token()
        assert access_token.access_token == 'mock_access_token'
        assert isinstance(access_token.expiry, datetime.datetime)
コード例 #10
0
    def test_init_from_file(self):
        credential = credentials.RefreshToken(
            testutils.resource_filename('refresh_token.json'))
        assert credential.client_id == 'mock.apps.googleusercontent.com'
        assert credential.client_secret == 'mock-secret'
        assert credential.refresh_token == 'mock-refresh-token'

        g_credential = credential.get_credential()
        assert isinstance(g_credential, gcredentials.Credentials)
        assert g_credential.token is None
        check_scopes(g_credential)

        mock_response = {
            'access_token': 'mock_access_token',
            'expires_in': 3600
        }
        credentials._request = testutils.MockRequest(200, json.dumps(mock_response))
        access_token = credential.get_access_token()
        assert access_token.access_token == 'mock_access_token'
        assert isinstance(access_token.expiry, datetime.datetime)
コード例 #11
0
 def test_init_from_invalid_certificate(self, file_name, error):
     with pytest.raises(error):
         credentials.Certificate(testutils.resource_filename(file_name))
コード例 #12
0
 def test_init_from_file(self):
     credential = credentials.Certificate(
         testutils.resource_filename('service_account.json'))
     self._verify_credential(credential)
コード例 #13
0
 def test_init_from_invalid_file(self):
     with pytest.raises(ValueError):
         credentials.RefreshToken(
             testutils.resource_filename('service_account.json'))
コード例 #14
0
 def test_init_from_nonexisting_file(self):
     with pytest.raises(IOError):
         credentials.RefreshToken(
             testutils.resource_filename('non_existing.json'))
コード例 #15
0
 def test_init_from_file(self):
     credential = credentials.RefreshToken(
         testutils.resource_filename('refresh_token.json'))
     self._verify_credential(credential)
コード例 #16
0
 def init(self):
     self.file_path = os.environ.get(self.VAR_NAME)
     os.environ[self.VAR_NAME] = testutils.resource_filename(
         'service_account.json')
コード例 #17
0
 def test_init_from_path_like(self):
     path = pathlib.Path(
         testutils.resource_filename('service_account.json'))
     credential = credentials.Certificate(path)
     self._verify_credential(credential)
コード例 #18
0
def setup_module():
    cred = credentials.Certificate(testutils.resource_filename('service_account.json'))
    firebase_admin.initialize_app(cred)
コード例 #19
0
def tenant_aware_custom_token_app():
    cred = credentials.Certificate(
        testutils.resource_filename('service_account.json'))
    app = firebase_admin.initialize_app(cred, name='tenantAwareCustomToken')
    yield app
    firebase_admin.delete_app(app)
コード例 #20
0
import pytest
import six

import firebase_admin
from firebase_admin import auth
from firebase_admin import credentials
from firebase_admin import _user_mgt
from tests import testutils

FIREBASE_AUDIENCE = ('https://identitytoolkit.googleapis.com/'
                     'google.identity.identitytoolkit.v1.IdentityToolkit')
GCLOUD_PROJECT_ENV_VAR = 'GCLOUD_PROJECT'

MOCK_UID = 'user1'
MOCK_CREDENTIAL = credentials.Certificate(
    testutils.resource_filename('service_account.json'))
MOCK_PUBLIC_CERTS = testutils.resource('public_certs.json')
MOCK_PRIVATE_KEY = testutils.resource('private_key.pem')
MOCK_SERVICE_ACCOUNT_EMAIL = MOCK_CREDENTIAL.service_account_email

INVALID_STRINGS = [None, '', 0, 1, True, False, list(), tuple(), dict()]
INVALID_BOOLS = [None, '', 'foo', 0, 1, list(), tuple(), dict()]
INVALID_DICTS = [None, 'foo', 0, 1, True, False, list(), tuple()]

MOCK_GET_USER_RESPONSE = testutils.resource('get_user.json')


class AuthFixture(object):
    def __init__(self, name=None):
        if name:
            self.app = firebase_admin.get_app(name)
コード例 #21
0
 def get(self):
     return credentials.RefreshToken(
         testutils.resource_filename('refresh_token.json'))
コード例 #22
0
ファイル: test_db.py プロジェクト: nlbrown2/RPi-Lights-Server
def testdata():
    with open(testutils.resource_filename('dinosaurs.json')) as dino_file:
        return json.load(dino_file)
コード例 #23
0
 def test_init_from_path_like(self):
     path = pathlib.Path(testutils.resource_filename('refresh_token.json'))
     credential = credentials.RefreshToken(path)
     self._verify_credential(credential)