|
10 | 10 | NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
|
11 | 11 | """
|
12 | 12 |
|
| 13 | +import unittest |
13 | 14 | from unittest import IsolatedAsyncioTestCase
|
14 | 15 |
|
15 | 16 | import openfga_sdk
|
16 | 17 | from openfga_sdk.credentials import CredentialConfiguration, Credentials
|
| 18 | +from openfga_sdk.exceptions import ApiValueError |
17 | 19 |
|
18 | 20 |
|
19 | 21 | class TestCredentials(IsolatedAsyncioTestCase):
|
@@ -172,3 +174,61 @@ def test_configuration_client_credentials_missing_api_audience(self):
|
172 | 174 | )
|
173 | 175 | with self.assertRaises(openfga_sdk.ApiValueError):
|
174 | 176 | credential.validate_credentials_config()
|
| 177 | + |
| 178 | + |
| 179 | +class TestCredentialsIssuer(unittest.TestCase): |
| 180 | + def setUp(self): |
| 181 | + # Setup a basic configuration that can be modified per test case |
| 182 | + self.configuration = CredentialConfiguration(api_issuer="https://example.com") |
| 183 | + self.credentials = Credentials( |
| 184 | + method="client_credentials", configuration=self.configuration |
| 185 | + ) |
| 186 | + |
| 187 | + def test_valid_issuer_https(self): |
| 188 | + # Test a valid HTTPS URL |
| 189 | + self.configuration.api_issuer = "issuer.fga.example " |
| 190 | + result = self.credentials._parse_issuer(self.configuration.api_issuer) |
| 191 | + self.assertEqual(result, "https://issuer.fga.example/oauth/token") |
| 192 | + |
| 193 | + def test_valid_issuer_with_oauth_endpoint_https(self): |
| 194 | + # Test a valid HTTPS URL |
| 195 | + self.configuration.api_issuer = "https://example.com/oauth/token" |
| 196 | + result = self.credentials._parse_issuer(self.configuration.api_issuer) |
| 197 | + self.assertEqual(result, "https://example.com/oauth/token") |
| 198 | + |
| 199 | + def test_valid_issuer_with_some_endpoint_https(self): |
| 200 | + # Test a valid HTTPS URL |
| 201 | + self.configuration.api_issuer = "https://example.com/oauth/some/endpoint" |
| 202 | + result = self.credentials._parse_issuer(self.configuration.api_issuer) |
| 203 | + self.assertEqual(result, "https://example.com/oauth/some/endpoint") |
| 204 | + |
| 205 | + def test_valid_issuer_http(self): |
| 206 | + # Test a valid HTTP URL |
| 207 | + self.configuration.api_issuer = "fga.example/some_endpoint" |
| 208 | + result = self.credentials._parse_issuer(self.configuration.api_issuer) |
| 209 | + self.assertEqual(result, "https://fga.example/some_endpoint") |
| 210 | + |
| 211 | + def test_invalid_issuer_no_scheme(self): |
| 212 | + # Test an issuer URL without a scheme |
| 213 | + self.configuration.api_issuer = "https://issuer.fga.example:8080/some_endpoint " |
| 214 | + result = self.credentials._parse_issuer(self.configuration.api_issuer) |
| 215 | + self.assertEqual(result, "https://issuer.fga.example:8080/some_endpoint") |
| 216 | + |
| 217 | + def test_invalid_issuer_bad_scheme(self): |
| 218 | + # Test an issuer with an unsupported scheme |
| 219 | + self.configuration.api_issuer = "ftp://example.com" |
| 220 | + with self.assertRaises(ApiValueError): |
| 221 | + self.credentials._parse_issuer(self.configuration.api_issuer) |
| 222 | + |
| 223 | + def test_invalid_issuer_with_port(self): |
| 224 | + # Test an issuer with an unsupported scheme |
| 225 | + self.configuration.api_issuer = "https://issuer.fga.example:8080 " |
| 226 | + result = self.credentials._parse_issuer(self.configuration.api_issuer) |
| 227 | + self.assertEqual(result, "https://issuer.fga.example:8080/oauth/token") |
| 228 | + |
| 229 | + # this should raise error |
| 230 | + def test_invalid_issuer_bad_hostname(self): |
| 231 | + # Test an issuer with an invalid hostname |
| 232 | + self.configuration.api_issuer = "https://example?.com" |
| 233 | + with self.assertRaises(ApiValueError): |
| 234 | + self.credentials._parse_issuer(self.configuration.api_issuer) |
0 commit comments