Add tests for class OpenStackIdentity_3_0_Connection_OIDC_access_token

Closes #789

Signed-off-by: Tomaz Muraus <to...@tomaz.me>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/b0cae9e6
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/b0cae9e6
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/b0cae9e6

Branch: refs/heads/trunk
Commit: b0cae9e60e2c9dfeba7243e88c05e3293f85078e
Parents: 6de1d14
Author: micafer <micaf...@upv.es>
Authored: Fri May 20 09:34:34 2016 +0200
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Thu May 26 20:53:20 2016 +0200

----------------------------------------------------------------------
 libcloud/test/common/test_openstack_identity.py | 45 ++++++++++++++++++--
 1 file changed, 42 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/b0cae9e6/libcloud/test/common/test_openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/test/common/test_openstack_identity.py 
b/libcloud/test/common/test_openstack_identity.py
index 456162d..0829094 100644
--- a/libcloud/test/common/test_openstack_identity.py
+++ b/libcloud/test/common/test_openstack_identity.py
@@ -30,6 +30,7 @@ from libcloud.common.openstack_identity import 
get_class_for_auth_version
 from libcloud.common.openstack_identity import OpenStackServiceCatalog
 from libcloud.common.openstack_identity import OpenStackIdentity_2_0_Connection
 from libcloud.common.openstack_identity import OpenStackIdentity_3_0_Connection
+from libcloud.common.openstack_identity import 
OpenStackIdentity_3_0_Connection_OIDC_access_token
 from libcloud.common.openstack_identity import OpenStackIdentityUser
 from libcloud.compute.drivers.openstack import OpenStack_1_0_NodeDriver
 
@@ -424,6 +425,30 @@ class 
OpenStackIdentity_3_0_ConnectionTests(unittest.TestCase):
         self.assertTrue(result)
 
 
+class OpenStackIdentity_3_0_Connection_OIDC_access_tokenTests(
+        unittest.TestCase):
+    def setUp(self):
+        mock_cls = OpenStackIdentity_3_0_MockHttp
+        mock_cls.type = None
+        OpenStackIdentity_3_0_Connection_OIDC_access_token.conn_classes = 
(mock_cls, mock_cls)
+
+        self.auth_instance = 
OpenStackIdentity_3_0_Connection_OIDC_access_token(auth_url='http://none',
+                                                                               
 user_id='idp',
+                                                                               
 key='token',
+                                                                               
 tenant_name='oidc',
+                                                                               
 domain_name='test_domain')
+        self.auth_instance.auth_token = 'mock'
+
+    def test_authenticate(self):
+        auth = 
OpenStackIdentity_3_0_Connection_OIDC_access_token(auth_url='http://none',
+                                                                  
user_id='idp',
+                                                                  key='token',
+                                                                  
token_scope='project',
+                                                                  
tenant_name="oidc",
+                                                                  
domain_name='test_domain')
+        auth.authenticate()
+
+
 class OpenStackServiceCatalogTestCase(unittest.TestCase):
     fixtures = ComputeFileFixtures('openstack')
 
@@ -587,9 +612,10 @@ class OpenStackIdentity_3_0_MockHttp(MockHttp):
         if method == 'POST':
             status = httplib.OK
             data = json.loads(body)
-            if data['auth']['identity']['password']['user']['domain']['name'] 
!= 'test_domain' or \
-                    data['auth']['scope']['project']['domain']['name'] != 
'test_domain':
-                status = httplib.UNAUTHORIZED
+            if 'password' in data['auth']['identity']:
+                if 
data['auth']['identity']['password']['user']['domain']['name'] != 'test_domain' 
or \
+                        data['auth']['scope']['project']['domain']['name'] != 
'test_domain':
+                    status = httplib.UNAUTHORIZED
 
             body = ComputeFileFixtures('openstack').load('_v3__auth.json')
             headers = self.json_content_headers.copy()
@@ -669,6 +695,19 @@ class OpenStackIdentity_3_0_MockHttp(MockHttp):
             return (httplib.OK, body, self.json_content_headers, 
httplib.responses[httplib.OK])
         raise NotImplementedError()
 
+    def _v3_OS_FEDERATION_identity_providers_idp_protocols_oidc_auth(self, 
method, url, body, headers):
+        if method == 'GET':
+            headers = self.json_content_headers.copy()
+            headers['x-subject-token'] = '00000000000000000000000000000000'
+            return (httplib.OK, body, headers, httplib.responses[httplib.OK])
+        raise NotImplementedError()
+
+    def _v3_OS_FEDERATION_projects(self, method, url, body, headers):
+        if method == 'GET':
+            # get user projects
+            body = json.dumps({"projects": [{"id": "project_id"}]})
+            return (httplib.OK, body, self.json_content_headers, 
httplib.responses[httplib.OK])
+        raise NotImplementedError()
 
 if __name__ == '__main__':
     sys.exit(unittest.main())

Reply via email to