Skip to content

Commit 37d9cdc

Browse files
szhGitHub Enterprise
authored andcommitted
Merge pull request #23 from Conjur-Enterprise/fix-53
CNJR-9054: Fix logging errors
2 parents ae6f04b + 7e79bb6 commit 37d9cdc

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9-
## [0.1.4] - 2025-03-25
9+
## [0.1.4] - 2025-03-26
10+
11+
### Fixed
12+
- Fixed logging errors
13+
[cyberark/conjur-api-python#53](https://github.com/cyberark/conjur-api-python/issues/53), CNJR-9054
1014

1115
## [0.1.3] - 2025-02-24
1216

@@ -65,6 +69,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6569
- Store API key in `CreditentialsData` object
6670
[conjur-api-python#23](https://github.com/cyberark/conjur-api-python/pull/23)
6771

68-
[Unreleased]: https://github.com/cyberark/conjur-api-python/compare/v0.1.1...HEAD
72+
[Unreleased]: https://github.com/cyberark/conjur-api-python/compare/v0.1.4...HEAD
73+
[0.1.4]: https://github.com/cyberark/conjur-api-python/compare/v0.1.3...v0.1.4
74+
[0.1.3]: https://github.com/cyberark/conjur-api-python/compare/v0.1.2...v0.1.3
75+
[0.1.2]: https://github.com/cyberark/conjur-api-python/compare/v0.1.1...v0.1.2
6976
[0.1.1]: https://github.com/cyberark/conjur-api-python/compare/v0.1.0...v0.1.1
7077
[0.1.0]: https://github.com/cyberark/conjur-api-python/releases/tag/v0.1.0

conjur_api/http/ssl/ssl_context_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def create_ssl_context(ssl_verification_metadata: SslVerificationMetadata) -> ss
2929
os_type = get_current_os()
3030

3131
if ssl_verification_metadata.mode == SslVerificationMode.TRUST_STORE:
32-
logging.debug("Creating SSLContext from OS TrustStore for '%d'", os_type)
32+
logging.debug("Creating SSLContext from OS TrustStore for '%s'", os_type.name)
3333
ssl_context = _create_ssl_context(os_type)
3434
else:
3535
ssl_context = ssl.create_default_context(cafile=ssl_verification_metadata.ca_cert_path)

conjur_api/wrappers/http_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ def json(self) -> json:
5454
return json.loads(self.text)
5555

5656
def __repr__(self):
57-
return f"{{'status': {self.status}, 'content length': '{len(self.content)}'}}"
57+
return f"{{'status': {self.status}, 'content length': '{len(self.content) if self.content else 0}'}}"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import io
2+
import logging
3+
4+
from aiounittest import AsyncTestCase
5+
6+
from conjur_api.http.ssl import ssl_context_factory
7+
from conjur_api.models import SslVerificationMetadata, SslVerificationMode
8+
9+
10+
class SslContextFactoryTest(AsyncTestCase):
11+
async def test_create_ssl_context_with_trust_store(self):
12+
# Redirect logging to a buffer
13+
log_stream = io.StringIO()
14+
log_output = logging.StreamHandler(log_stream)
15+
logging.getLogger().addHandler(log_output)
16+
original_level = logging.getLogger().level
17+
logging.getLogger().setLevel(logging.DEBUG)
18+
19+
# Create SSLContext with TrustStore
20+
ssl_verification_metadata = SslVerificationMetadata(SslVerificationMode.TRUST_STORE)
21+
ssl_context = ssl_context_factory.create_ssl_context(ssl_verification_metadata)
22+
self.assertIsNotNone(ssl_context)
23+
24+
# Remove the handler
25+
logging.getLogger().removeHandler(log_output)
26+
logging.getLogger().setLevel(original_level)
27+
28+
# Verify the log output
29+
log_stream.seek(0)
30+
self.assertIn("Creating SSLContext from OS TrustStore for 'LINUX'", log_stream.read())

tests/integration/integ_utils.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
from enum import Enum
22
from typing import Optional
33

4-
from conjur_api import Client, AuthenticationStrategyInterface
4+
from conjur_api import AuthenticationStrategyInterface, Client
55
from conjur_api.models import CredentialsData, SslVerificationMode
6-
from conjur_api.models.general.conjur_connection_info import ConjurConnectionInfo
7-
from conjur_api.providers import SimpleCredentialsProvider, AuthnAuthenticationStrategy, LdapAuthenticationStrategy
8-
from conjur_api.providers.oidc_authentication_strategy import OidcAuthenticationStrategy
9-
from conjur_api.providers.jwt_authentication_strategy import JWTAuthenticationStrategy
6+
from conjur_api.models.general.conjur_connection_info import \
7+
ConjurConnectionInfo
8+
from conjur_api.providers import (AuthnAuthenticationStrategy,
9+
LdapAuthenticationStrategy,
10+
SimpleCredentialsProvider)
11+
from conjur_api.providers.jwt_authentication_strategy import \
12+
JWTAuthenticationStrategy
13+
from conjur_api.providers.oidc_authentication_strategy import \
14+
OidcAuthenticationStrategy
1015

1116

1217
class ConjurUser:
@@ -47,4 +52,4 @@ async def create_client(username: str, password: str,
4752
authn_strategy = AuthnAuthenticationStrategy(credentials_provider)
4853

4954
return Client(conjur_data, authn_strategy=authn_strategy,
50-
ssl_verification_mode=SslVerificationMode.INSECURE)
55+
ssl_verification_mode=SslVerificationMode.INSECURE, debug=True)

tests/integration/test_integration_vanila.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async def test_integration_vanilla_ldap(self):
5757
credentials = CredentialsData(username=username, password=password, machine=conjur_url)
5858
credentials_provider.save(credentials)
5959
c = Client(conjur_data, authn_strategy=authn_provider,
60-
ssl_verification_mode=SslVerificationMode.INSECURE)
60+
ssl_verification_mode=SslVerificationMode.INSECURE, debug=True)
6161
resources = await c.list()
6262
self.assertEqual(len(resources), 2)
6363

0 commit comments

Comments
 (0)