Exemplo n.º 1
0
    def test_url(self):
        url = "http://ikeystone.yy.com/v1/"
        api = ikeys_cli.IKeytoneAPI(url)
        api_url, method = api._get_url_and_method(api.domain.request.verify)
        self.assertEqual(
            api_url,
            "http://ikeystone.yy.com/v1/domain/verifyRequest",
        )
        self.assertEqual(
            method,
            "POST",
        )

        url = "http://ikeystone.yy.com/v1"
        api = ikeys_cli.IKeytoneAPI(url)
        api_url, method = api._get_url_and_method(api.domain.request.verify)
Exemplo n.º 2
0
    def test_get_result_from_response3(self):
        url = "http://ikeystone.yy.com/v1/"
        api = ikeys_cli.IKeytoneAPI(url)
        self.request_mock.return_value = mock.MagicMock(
            json=mock.MagicMock(side_effect=ValueError, ))

        with self.assertRaises(ikeys_cli.ResultParseError):
            api.test.check()
Exemplo n.º 3
0
    def test_get_result_from_response2(self):
        url = "http://ikeystone.yy.com/v1/"
        api = ikeys_cli.IKeytoneAPI(url)
        return_value = {
            "errno": 0,
            "data": id(self),
        }
        self.request_mock.return_value = mock.MagicMock(
            json=mock.MagicMock(return_value=return_value, ))

        result = api.test.check()
        self.assertEqual(result.errno, 0)
        self.assertEqual(result.errmsg, None)
        self.assertEqual(result.data, id(self))
Exemplo n.º 4
0
    def test_get_authentication_headers(self):
        url = "http://ikeystone.yy.com/v1/"
        api = ikeys_cli.IKeytoneAPI(url)
        domain = "domain"
        user = "******"
        password = "******"

        api.authenticate(domain, user, password)
        headers = api.get_authentication_headers()
        self.assertDictContainsSubset(
            {
                "X-AUTH-DOMAIN": domain,
                "X-AUTH-USER": user,
            }, headers)
        self.assertNotIn("X-AUTH-PROJECT", headers)
Exemplo n.º 5
0
 def test_construction(self):
     api = ikeys_cli.IKeytoneAPI("http://ikeystone.yy.com")
     self.assertEqual(
         api.test.check._url_path,
         self.test_path,
     )
     self.assertEqual(
         api.test.check._method,
         "POST",
     )
     url, method = api._get_url_and_method(api.test.check)
     self.assertEqual(
         url, "http://ikeystone.yy.com/%s" % api.test.check._url_path)
     self.assertEqual(method, api.test.check._method)
     url, method = api._get_url_and_method(api.nothing.to.get)
     self.assertEqual(url, "http://ikeystone.yy.com/nothing/to")
     self.assertEqual(method, "GET")
Exemplo n.º 6
0
    def test_get_result_from_response1(self):
        url = "http://ikeystone.yy.com/v1/"
        api = ikeys_cli.IKeytoneAPI(url)

        data = {"value": 1}
        api.test.check(data=data)
        self.request_mock.assert_called_with(
            url=url + self.test_path,
            method="POST",
            json=data,
            headers=api._headers,
        )

        api.test.get(data=data)
        self.request_mock.assert_called_with(
            url=url + self.test_path,
            method="GET",
            params=data,
            headers=api._headers,
        )
Exemplo n.º 7
0
    def test_domain_verify_request(self):
        url = "http://ikeystone.yy.com/v1/"
        api = ikeys_cli.IKeytoneAPI(url)

        domain = "my_domain"
        user = "******"
        password = "******"
        project = "my_project"
        api.authenticate(domain, user, password, project)

        response_data = {
            "domain": domain,
            "user": user,
            project: "my_project",
            "expires": "1598b5b3eb7",
            "nonce": "74a465fddab8b",
            "api": "api_name_0",
            "signature": "56f8519d7f31460821e4722de0c77c5f",
            "roles": ["SERVICE"],
        }
        self.request_mock.return_value = mock.MagicMock(json=mock.MagicMock(
            return_value={
                "errno": 0,
                "data": response_data
            }))

        result = api.domain.request.verify(
            data={
                "domain": domain,
                "user": user,
                project: "my_project",
                "expires": "1598b5b3eb7",
                "nonce": "74a465fddab8b",
                "api": "api_name_0",
                "signature": "56f8519d7f31460821e4722de0c77c5f",
            })
        data = result.data
        self.assertEqual(result.errno, 0)
        self.assertEqual(result.errmsg, None)
        self.assertEqual(data, response_data)
Exemplo n.º 8
0
    def test_get_result_from_response4(self):
        url = "http://ikeystone.yy.com/v1/"
        api = ikeys_cli.IKeytoneAPI(url)
        self.request_mock.return_value = mock.MagicMock(
            json=mock.MagicMock(return_value={}, ))
        domain = "domain"
        user = "******"
        password = "******"
        project = "project"
        api.authenticate(domain, user, password, project)
        headers = {}

        api.test.check(headers=headers)

        self.assertDictContainsSubset(
            {
                "X-AUTH-DOMAIN": domain,
                "X-AUTH-USER": user,
            }, headers)
        self.assertIsInstance(headers["X-AUTH-EXPIRES"], str)
        self.assertIsInstance(headers["X-AUTH-NONCE"], str)
        self.assertIsInstance(headers["X-AUTH-SIGNATURE"], str)