Skip to content

Commit

Permalink
DXE-884 further .edgerc validation
Browse files Browse the repository at this point in the history
  • Loading branch information
robertolopezlopez committed Apr 7, 2022
1 parent d12c143 commit 17b2e88
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions httpie_edgegrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ def get_auth(self, username: str = None, password: str = None):

try:
rc = EdgeRc(rc_path)
except configparser.MissingSectionHeaderError as e:
except (configparser.DuplicateSectionError, configparser.MissingSectionHeaderError, UnicodeDecodeError):
err_msg = '''
ERROR: {0} is not a valid .edgerc file
ERROR: Please generate credentials for the script functionality
ERROR: and run 'python gen_edgerc.py %s' to generate the credential file
'''.format(e.source)
'''.format(rc_path)
sys.stderr.write(err_msg)
sys.exit(2)

Expand Down
14 changes: 13 additions & 1 deletion test/test_httpie_edgegrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,24 @@ def test_bad_rc_path(self):
self._test_case("https://localhost/", self._host, "default")
self.assertEqual(1, err_msg.exception.code)

def test_bad_rc_file(self):
def test_bad_rc_file_format(self):
with self.assertRaises(SystemExit) as err_msg:
os.environ["RC_PATH"] = normalize_path('test_httpie_edgegrid.py')
self._test_case("https://localhost/", self._host, "default")
self.assertEqual(2, err_msg.exception.code)

def test_duplicated_rc_file_section(self):
with self.assertRaises(SystemExit) as err_msg:
os.environ["RC_PATH"] = normalize_path('testfiles/sample_edgerc_duplicated_section')
self._test_case("https://localhost/", self._host, "default")
self.assertEqual(2, err_msg.exception.code)

def test_binary(self):
with self.assertRaises(SystemExit) as err_msg:
os.environ["RC_PATH"] = normalize_path('testfiles/binary')
self._test_case("https://localhost/", self._host, "default")
self.assertEqual(2, err_msg.exception.code)

def test_bad_rc_entry(self):
with self.assertRaises(SystemExit) as err:
self._test_case("https://localhost/", self._host, "not_default")
Expand Down
Binary file added test/testfiles/binary
Binary file not shown.
14 changes: 14 additions & 0 deletions test/testfiles/sample_edgerc_duplicated_section
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[default]
host = xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.luna.akamaiapis.net/
client_token = xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx
client_secret = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
access_token = xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx
max_body = 131072

[default]
host = xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.luna.akamaiapis.net/
client_token = xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx
client_secret = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
access_token = xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx
max_body = 131072

0 comments on commit 17b2e88

Please sign in to comment.