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

Dollar sign escape #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pyipmi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,18 @@ def set_auth_type_user(self, username, password):

@property
def auth_username(self):
return self._auth_username
return self._escape_dollar_sign(self._auth_username)

@property
def auth_password(self):
return self._auth_password
return self._escape_dollar_sign(self._auth_password)

def _escape_dollar_sign(self, password):
"""Escape string with dollar sign in ipmitool."""
# The IPMI command is built and executed in a shell using Popen.
# The '$_' combination has its own behavior in shell and it gets
# replaced in the string.
return password.replace('$', '\\$')

def establish(self):
if hasattr(self.interface, 'establish_session'):
Expand Down
22 changes: 22 additions & 0 deletions tests/test_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pyipmi.session import Session
from subprocess import Popen, PIPE


def test_auth_username():
username = 'ad$_min'
password = 'password'
session = Session()
session.set_auth_type_user(username, password)
child = Popen(f"echo {session.auth_username}", shell=True, stdout=PIPE)
output = child.communicate()[0].decode('utf-8').strip()
assert output == username


def test_auth_password():
username = 'admin'
password = 'pass$_word'
session = Session()
session.set_auth_type_user(username, password)
child = Popen(f"echo {session.auth_password}", shell=True, stdout=PIPE)
output = child.communicate()[0].decode('utf-8').strip()
assert output == password
Loading