Skip to content

Commit c31db0d

Browse files
committed
Fix for #26
- Check that we have a token before trying to save a command. Would previously 403 for users that were not logged in.
1 parent 608061b commit c31db0d

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

bashhub/bashhub.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ def save(command, path, pid, process_start_time, exit_status):
6060
if bh_filter and re.findall(bh_filter, command):
6161
return
6262

63+
# Check that we have an auth token.
64+
if bashhub_globals.BH_AUTH() == "":
65+
print("No auth token found. Run 'bashhub setup' to login.")
66+
return
67+
6368
command = CommandForm(command, path, exit_status, pid, pid_start_time)
6469
rest_client.save_command(command)
6570

bashhub/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.0.0'
1+
__version__ = '1.0.1-dev'

tests/test_bashhub.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ def print_failed(command):
4040
result = runner.invoke(bashhub, args)
4141
assert '' == result.output
4242

43+
def no_auth_token():
44+
return ''
45+
46+
# Should not try to save a command if we don't have an auth token
47+
bashhub_globals.BH_AUTH = no_auth_token
48+
result = runner.invoke(bashhub, ['save', 'date', '/tmp', '1', '1000','1'])
49+
error_message = "No auth token found. Run 'bashhub setup' to login.\n"
50+
assert error_message == result.output
51+
4352
def test_bashhub_version():
4453
runner = CliRunner()
4554
result = runner.invoke(bashhub, ['version'])

0 commit comments

Comments
 (0)