示例#1
0
 def test_credentials_which_cannot_be_encoded_in_unicode_work(self):
     badCredentials = {
         'accessToken': u"\U0001F4A9",
         'clientId': u"\U0001F4A9",
     }
     with self.assertRaises(exc.TaskclusterAuthFailure):
         subject.Auth({'credentials': badCredentials})
示例#2
0
 def test_invalid_unicode_permacred_simple(self):
     """Unicode strings that do not encode to ASCII in credentials cause issues"""
     with self.assertRaises(exc.TaskclusterAuthFailure):
         subject.Auth({
             'credentials': {
                 'clientId': u"\U0001F4A9",
                 'accessToken': u"\U0001F4A9",
             }
         })
示例#3
0
def test_credentials_which_cannot_be_encoded_in_unicode_work():
    badCredentials = {
        'accessToken': u"\U0001F4A9",
        'clientId': u"\U0001F4A9",
    }
    with pytest.raises(exc.TaskclusterAuthFailure):
        subject.Auth({
            'rootUrl': base.REAL_ROOT_URL,
            'credentials': badCredentials,
        })
示例#4
0
def test_invalid_unicode_permacred_simple():
    """Unicode strings that do not encode to ASCII in credentials cause issues"""
    with pytest.raises(exc.TaskclusterAuthFailure):
        subject.Auth({
            'rootUrl': base.TEST_ROOT_URL,
            'credentials': {
                'clientId': u"\U0001F4A9",
                'accessToken': u"\U0001F4A9",
            }
        })
示例#5
0
 def test_signed_url_bad_credentials(self):
     client = subject.Auth({
         'credentials': {
             'clientId': 'tester',
             'accessToken': 'wrong-secret',
         }
     })
     signedUrl = client.buildSignedUrl('testAuthenticateGet')
     response = requests.get(signedUrl)
     with self.assertRaises(requests.exceptions.RequestException):
         response.raise_for_status()
     self.assertEqual(401, response.status_code)
示例#6
0
 def test_unicode_permacred_simple(self):
     """Unicode strings that encode to ASCII in credentials do not cause issues"""
     client = subject.Auth({
         'credentials': {
             'clientId': u'tester',
             'accessToken': u'no-secret',
         }
     })
     result = client.testAuthenticate({
         'clientScopes': ['test:a'],
         'requiredScopes': ['test:a'],
     })
     self.assertEqual(result, {'scopes': ['test:a'], 'clientId': 'tester'})
示例#7
0
def test_signed_url_bad_credentials():
    client = subject.Auth({
        'rootUrl': base.REAL_ROOT_URL,
        'credentials': {
            'clientId': 'tester',
            'accessToken': 'wrong-secret',
        }
    })
    signedUrl = client.buildSignedUrl('testAuthenticateGet')
    response = requests.get(signedUrl)
    with pytest.raises(requests.exceptions.RequestException):
        response.raise_for_status()
    assert 401 == response.status_code
示例#8
0
def test_permacred_insufficient_scopes():
    """A call with insufficient scopes results in an error"""
    client = subject.Auth({
        'rootUrl': base.REAL_ROOT_URL,
        'credentials': {
            'clientId': 'tester',
            'accessToken': 'no-secret',
        }
    })
    with pytest.raises(exc.TaskclusterRestFailure):
        client.testAuthenticate({
            'clientScopes': ['test:*'],
            'requiredScopes': ['something-more'],
        })
示例#9
0
def test_unicode_permacred_simple():
    """Unicode strings that encode to ASCII in credentials do not cause issues"""
    client = subject.Auth({
        'rootUrl': base.REAL_ROOT_URL,
        'credentials': {
            'clientId': u'tester',
            'accessToken': u'no-secret',
        }
    })
    result = client.testAuthenticate({
        'clientScopes': ['test:a'],
        'requiredScopes': ['test:a'],
    })
    assert result == {'scopes': ['test:a'], 'clientId': 'tester'}
示例#10
0
def test_permacred_simple_authorizedScopes():
    client = subject.Auth({
        'rootUrl': base.REAL_ROOT_URL,
        'credentials': {
            'clientId': 'tester',
            'accessToken': 'no-secret',
        },
        'authorizedScopes': ['test:a', 'test:b'],
    })
    result = client.testAuthenticate({
        'clientScopes': ['test:*'],
        'requiredScopes': ['test:a'],
    })
    assert result == {'scopes': ['test:a', 'test:b'], 'clientId': 'tester'}
示例#11
0
 def test_permacred_simple(self):
     """we can call methods which require authentication with valid
     permacreds"""
     client = subject.Auth({
         'credentials': {
             'clientId': 'tester',
             'accessToken': 'no-secret',
         }
     })
     result = client.testAuthenticate({
         'clientScopes': ['test:a'],
         'requiredScopes': ['test:a'],
     })
     self.assertEqual(result, {'scopes': ['test:a'], 'clientId': 'tester'})
示例#12
0
def test_permacred_simple():
    """we can call methods which require authentication with valid
    permacreds"""
    client = subject.Auth({
        'rootUrl': base.REAL_ROOT_URL,
        'credentials': {
            'clientId': 'tester',
            'accessToken': 'no-secret',
        }
    })
    result = client.testAuthenticate({
        'clientScopes': ['test:a'],
        'requiredScopes': ['test:a'],
    })
    assert result == {'scopes': ['test:a'], 'clientId': 'tester'}
示例#13
0
 def test_permacred_insufficient_scopes(self):
     """A call with insufficient scopes results in an error"""
     client = subject.Auth({
         'credentials': {
             'clientId': 'tester',
             'accessToken': 'no-secret',
         }
     })
     # TODO: this should be TaskclsuterAuthFailure; most likely the client
     # is expecting AuthorizationFailure instead of AuthenticationFailure
     with self.assertRaises(exc.TaskclusterRestFailure):
         client.testAuthenticate({
             'clientScopes': ['test:*'],
             'requiredScopes': ['something-more'],
         })
示例#14
0
 def test_signed_url_authorizedScopes(self):
     client = subject.Auth({
         'credentials': {
             'clientId': 'tester',
             'accessToken': 'no-secret',
         },
         'authorizedScopes': ['test:authenticate-get'],
     })
     signedUrl = client.buildSignedUrl('testAuthenticateGet')
     response = requests.get(signedUrl)
     response.raise_for_status()
     response = response.json()
     self.assertEqual(response, {
         'scopes': ['test:authenticate-get'],
         'clientId': 'tester',
     })
示例#15
0
def test_no_creds_needed():
    """we can call methods which require no scopes with an unauthenticated
    client"""
    # mock this request so we don't depend on the existence of a client
    @httmock.all_requests
    def auth_response(url, request):
        assert urllib.parse.urlunsplit(url) == 'https://tc-tests.example.com/api/auth/v1/clients/abc'
        assert not ('Authorization' in request.headers)
        headers = {'content-type': 'application/json'}
        content = {"clientId": "abc"}
        return httmock.response(200, content, headers, None, 5, request)

    with httmock.HTTMock(auth_response):
        client = subject.Auth({"rootUrl": "https://tc-tests.example.com", "credentials": {}})
        result = client.client('abc')
        assert result == {"clientId": "abc"}
示例#16
0
 def test_permacred_simple_authorizedScopes(self):
     client = subject.Auth({
         'credentials': {
             'clientId': 'tester',
             'accessToken': 'no-secret',
         },
         'authorizedScopes': ['test:a', 'test:b'],
     })
     result = client.testAuthenticate({
         'clientScopes': ['test:*'],
         'requiredScopes': ['test:a'],
     })
     self.assertEqual(result, {
         'scopes': ['test:a', 'test:b'],
         'clientId': 'tester'
     })
示例#17
0
    def test_no_creds_needed(self):
        """we can call methods which require no scopes with an unauthenticated
        client"""
        # mock this request so we don't depend on the existence of a client
        @httmock.all_requests
        def auth_response(url, request):
            self.assertEqual(urllib.parse.urlunsplit(url),
                             'https://auth.taskcluster.net/v1/clients/abc')
            self.failIf('Authorization' in request.headers)
            headers = {'content-type': 'application/json'}
            content = {"clientId": "abc"}
            return httmock.response(200, content, headers, None, 5, request)

        with httmock.HTTMock(auth_response):
            client = subject.Auth({"credentials": {}})
            result = client.client('abc')
            self.assertEqual(result, {"clientId": "abc"})
示例#18
0
def test_named_temporary_credentials():
    tempCred = subject.createTemporaryCredentials(
        'tester',
        'no-secret',
        datetime.datetime.utcnow(),
        datetime.datetime.utcnow() + datetime.timedelta(hours=1), ['test:xyz'],
        name='credName')
    client = subject.Auth({
        'rootUrl': base.REAL_ROOT_URL,
        'credentials': tempCred,
    })

    result = client.testAuthenticate({
        'clientScopes': ['test:*', 'auth:create-client:credName'],
        'requiredScopes': ['test:xyz'],
    })
    assert result == {'scopes': ['test:xyz'], 'clientId': 'credName'}
示例#19
0
def test_signed_url_authorizedScopes():
    client = subject.Auth({
        'rootUrl': base.REAL_ROOT_URL,
        'credentials': {
            'clientId': 'tester',
            'accessToken': 'no-secret',
        },
        'authorizedScopes': ['test:authenticate-get'],
    })
    signedUrl = client.buildSignedUrl('testAuthenticateGet')
    response = requests.get(signedUrl)
    response.raise_for_status()
    response = response.json()
    assert response == {
        'scopes': ['test:authenticate-get'],
        'clientId': 'tester',
    }
示例#20
0
def test_signed_url():
    """we can use a signed url built with the python client"""
    client = subject.Auth({
        'rootUrl': base.REAL_ROOT_URL,
        'credentials': {
            'clientId': 'tester',
            'accessToken': 'no-secret',
        }
    })
    signedUrl = client.buildSignedUrl('testAuthenticateGet')
    response = requests.get(signedUrl)
    response.raise_for_status()
    response = response.json()
    response['scopes'].sort()
    assert response == {
        'scopes': sorted(['test:*', u'auth:create-client:test:*']),
        'clientId': 'tester',
    }
示例#21
0
def test_temporary_credentials_authorizedScopes():
    tempCred = subject.createTemporaryCredentials(
        'tester',
        'no-secret',
        datetime.datetime.utcnow(),
        datetime.datetime.utcnow() + datetime.timedelta(hours=1),
        ['test:xyz:*'],
    )
    client = subject.Auth({
        'rootUrl': base.REAL_ROOT_URL,
        'credentials': tempCred,
        'authorizedScopes': ['test:xyz:abc'],
    })

    result = client.testAuthenticate({
        'clientScopes': ['test:*'],
        'requiredScopes': ['test:xyz:abc'],
    })
    assert result == {'scopes': ['assume:anonymous', 'test:xyz:abc'], 'clientId': 'tester'}
示例#22
0
 def test_temp_credentials_signed_url(self):
     tempCred = subject.createTemporaryCredentials(
         'tester',
         'no-secret',
         datetime.datetime.utcnow(),
         datetime.datetime.utcnow() + datetime.timedelta(hours=1),
         ['test:*'],
     )
     client = subject.Auth({
         'credentials': tempCred,
     })
     signedUrl = client.buildSignedUrl('testAuthenticateGet')
     response = requests.get(signedUrl)
     response.raise_for_status()
     response = response.json()
     self.assertEqual(response, {
         'scopes': ['test:*'],
         'clientId': 'tester',
     })
示例#23
0
def test_temporary_credentials():
    """we can call methods which require authentication with temporary
    credentials generated by python client"""
    tempCred = subject.createTemporaryCredentials(
        'tester',
        'no-secret',
        datetime.datetime.utcnow(),
        datetime.datetime.utcnow() + datetime.timedelta(hours=1),
        ['test:xyz'],
    )
    client = subject.Auth({
        'rootUrl': base.REAL_ROOT_URL,
        'credentials': tempCred,
    })

    result = client.testAuthenticate({
        'clientScopes': ['test:*'],
        'requiredScopes': ['test:xyz'],
    })
    assert result == {'scopes': ['test:xyz'], 'clientId': 'tester'}
示例#24
0
def test_temp_credentials_signed_url():
    tempCred = subject.createTemporaryCredentials(
        'tester',
        'no-secret',
        datetime.datetime.utcnow(),
        datetime.datetime.utcnow() + datetime.timedelta(hours=1),
        ['test:*'],
    )
    client = subject.Auth({
        'rootUrl': base.REAL_ROOT_URL,
        'credentials': tempCred,
    })
    signedUrl = client.buildSignedUrl('testAuthenticateGet')
    response = requests.get(signedUrl)
    response.raise_for_status()
    response = response.json()
    assert response == {
        'scopes': ['assume:anonymous', 'test:*'],
        'clientId': 'tester',
    }
示例#25
0
    def test_named_temporary_credentials(self):
        tempCred = subject.createTemporaryCredentials(
            'tester',
            'no-secret',
            datetime.datetime.utcnow(),
            datetime.datetime.utcnow() + datetime.timedelta(hours=1),
            ['test:xyz'],
            name='credName')
        client = subject.Auth({
            'credentials': tempCred,
        })

        result = client.testAuthenticate({
            'clientScopes': ['test:*', 'auth:create-client:credName'],
            'requiredScopes': ['test:xyz'],
        })
        self.assertEqual(result, {
            'scopes': ['test:xyz'],
            'clientId': 'credName'
        })
示例#26
0
    def test_temporary_credentials_authorizedScopes(self):
        tempCred = subject.createTemporaryCredentials(
            'tester',
            'no-secret',
            datetime.datetime.utcnow(),
            datetime.datetime.utcnow() + datetime.timedelta(hours=1),
            ['test:xyz:*'],
        )
        client = subject.Auth({
            'credentials': tempCred,
            'authorizedScopes': ['test:xyz:abc'],
        })

        result = client.testAuthenticate({
            'clientScopes': ['test:*'],
            'requiredScopes': ['test:xyz:abc'],
        })
        self.assertEqual(result, {
            'scopes': ['test:xyz:abc'],
            'clientId': 'tester'
        })
示例#27
0
    def test_temporary_credentials(self):
        """we can call methods which require authentication with temporary
        credentials generated by python client"""
        tempCred = subject.createTemporaryCredentials(
            'tester',
            'no-secret',
            datetime.datetime.utcnow() - datetime.timedelta(hours=10),
            datetime.datetime.utcnow() + datetime.timedelta(hours=10),
            ['test:xyz'],
        )
        client = subject.Auth({
            'credentials': tempCred,
        })

        result = client.testAuthenticate({
            'clientScopes': ['test:*'],
            'requiredScopes': ['test:xyz'],
        })
        self.assertEqual(result, {
            'scopes': ['test:xyz'],
            'clientId': 'tester'
        })