From bd2ad191d977596a019aadcec8af6f7b1823f37d Mon Sep 17 00:00:00 2001 From: Nikolas Philips Date: Fri, 18 Feb 2022 12:08:54 +0100 Subject: [PATCH] fix(CredentialsHelper): Add single quotes around username/password to support special characters in credentials (#171) Co-authored-by: Nikolas Philips --- gitopscli/git_api/git_repo.py | 4 ++-- tests/git_api/test_git_repo.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gitopscli/git_api/git_repo.py b/gitopscli/git_api/git_repo.py index 1d8ee2f7..4c9a5734 100644 --- a/gitopscli/git_api/git_repo.py +++ b/gitopscli/git_api/git_repo.py @@ -109,7 +109,7 @@ def __create_credentials_file(self, username: str, password: str) -> str: file_path = f"{self.__tmp_dir}/credentials.sh" with open(file_path, "w") as text_file: text_file.write("#!/bin/sh\n") - text_file.write(f"echo username={username}\n") - text_file.write(f"echo password={password}\n") + text_file.write(f"echo username='{username}'\n") + text_file.write(f"echo password='{password}'\n") os.chmod(file_path, 0o700) return file_path diff --git a/tests/git_api/test_git_repo.py b/tests/git_api/test_git_repo.py index e1a8b870..82eb1b41 100644 --- a/tests/git_api/test_git_repo.py +++ b/tests/git_api/test_git_repo.py @@ -144,8 +144,8 @@ def test_clone_with_credentials(self, logging_mock): self.assertEqual( """\ #!/bin/sh -echo username=User -echo password=Pass +echo username='User' +echo password='Pass' """, credentials_file, )