Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

85 client silently ignores pem file if user expansion is needed #86

Merged

Conversation

tylern4
Copy link
Member

@tylern4 tylern4 commented Aug 13, 2024

Checks to get full path of file and if the file isn't found raises an error.

@tylern4 tylern4 linked an issue Aug 13, 2024 that may be closed by this pull request
@tylern4 tylern4 requested a review from cjh1 August 13, 2024 18:43
Copy link
Collaborator

@cjh1 cjh1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add to the docstring for key that is will be expanding using expanduser(), so it will be clear what the behavior will be. Can we also add a simple test to confirm the exception is throw?

src/sfapi_client/_async/client.py Show resolved Hide resolved
@tylern4
Copy link
Member Author

tylern4 commented Aug 27, 2024

I've added a few tests for the key file now.

Copy link
Collaborator

@cjh1 cjh1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks for adding the tests. One inline comment.

tests/conftest.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
temp_path = Path().home() / ".sfapi_test1"
if temp_path.exists():
(temp_path / "key.pem").unlink(missing_ok=True)
temp_path.rmdir()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry all the operations that could raise an exception should be in the try block, so like this:

   try:
       tmp_path_factory._basetemp = Path().home()
       key_path = tmp_path_factory.mktemp(".sfapi_test1", numbered=False) / "key.pem"

        # Make a fake key for testing
        key_path.write_text(
        f"""abcdefghijlmo
-----BEGIN RSA PRIVATE KEY-----
{rsa.generate_private_key(public_exponent=65537, key_size=2048)}
-----END RSA PRIVATE KEY-----
"""
        )
        key_path.chmod(0o100600)
        
        yield key_path
    finally:
        # make sure to cleanup the test since we put a file in ~/.sfapi_test
        temp_path = Path().home() / ".sfapi_test1"
        if temp_path.exists():
            (temp_path / "key.pem").unlink(missing_ok=True)
            temp_path.rmdir()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay makes sense!

Copy link
Collaborator

@cjh1 cjh1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for making the updates.

@tylern4 tylern4 merged commit 954ce1c into main Aug 28, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Client silently ignores PEM file if user expansion is needed
2 participants