[TACACS] Add UT to check TACACS will send remote address to server.#7702
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
tests/tacacs/test_accounting.py
Outdated
| # Extract received data from tac_plus.log, then use grep to check if the received data contains hex_string | ||
| sed_command = "sed -n 's/.*-> 0x\(..\).*/\\1/p' /var/log/tac_plus.log | sed ':a; N; $!ba; s/\\n//g' | grep '{0}'".format(hex_string) # noqa W605 E501 | ||
| res = ptfhost.shell(sed_command) | ||
| logger.info(sed_command) # lgtm [py/clear-text-logging-sensitive-data] |
| hex_string = hex.decode() | ||
|
|
||
| # Extract received data from tac_plus.log, then use grep to check if the received data contains hex_string | ||
| sed_command = "sed -n 's/.*-> 0x\(..\).*/\\1/p' /var/log/tac_plus.log | sed ':a; N; $!ba; s/\\n//g' | grep '{0}'".format(hex_string) # noqa W605 E501 |
There was a problem hiding this comment.
Fixed, add detail in comments:
W605 : Invalid escape sequence. Flake8 can't handle sed command escape sequence, so will report false alert.
E501 : Line too long. Following sed command difficult to split to multiple line.
| hex_string = hex.decode() | ||
|
|
||
| # Extract received data from tac_plus.log, then use grep to check if the received data contains hex_string | ||
| sed_command = "sed -n 's/.*-> 0x\(..\).*/\\1/p' /var/log/tac_plus.log | sed ':a; N; $!ba; s/\\n//g' | grep '{0}'".format(hex_string) # noqa W605 E501 |
There was a problem hiding this comment.
Fixed, add detail in comments:
-
tac_plus server start with '-d 2058' parameter to log received data in following format in tac_plus.log:
Thu Mar 9 06:26:16 2023 [75483]: data[140] = 0xf8, xor'ed with hash[12] = 0xab -> 0x53 Thu Mar 9 06:26:16 2023 [75483]: data[141] = 0x8d, xor'ed with hash[13] = 0xc2 -> 0x4fIn above log, the 'data[140] = 0xf8' is received data.
-
Following sed command will extract the received data from tac_plus.log:
sed -n 's/.-> 0x(..)./\1/p' /var/log/tac_plus.logSo the result will be: f8 8d -
Following set command will join all received data to hex string:
sed ':a; N; $!ba; s/\n//g'So the result will be: f88d..... -
Then the grep command will check if the received hex data containes expected hex string.
grep '{0}'".format(hex_string)
In our case, because we send remote address to TACACS server, so:
- we convert remote address to hex string:
"10.20.0.1" => 31302E32302E302E31 - We check if the received hex data contains "31302E32302E302E31", if it contains, then we know client do send remote address in TACACS+ package, so the UT passed.
|
The pre-commit check detected issues in the files touched by this pull request. For old issues, it is not mandatory to fix them because they were not caused by this change. It is unfair to blame Detailed pre-commit check results: To run the pre-commit checks locally, you can follow below steps:
|
What I did
Add UT to check TACACS will send remote address to server.
Why I did it
nss-tacplus add a patch to send remote address to server with this PR:sonic-net/sonic-buildimage#12190
To protect the patch, add this UT to check TACACS will send remote address to server.
How I verified it
Pass all UT.
Details if related