Skip to content

Commit 2daa6f9

Browse files
committed
Add cli integration
1 parent cdc51b3 commit 2daa6f9

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ $ pip install sssdldapauth
2626

2727
## Usage
2828

29+
**CLI**
30+
31+
```sh
32+
$ sssdldapauth deobfuscate <obfuscated_password>
33+
<password>
34+
```
35+
36+
**Library**
37+
2938
```python
3039
from sssdldapauth import deobfuscate
3140

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ packages = find:
1414
python_requires = >= 3.6
1515
include_package_data = True
1616
install_requires=
17+
click
1718
cryptography
1819

1920
[options.package_data]
2021
sssdldapauth = py.typed
22+
23+
[options.entry_points]
24+
console_scripts =
25+
sssdldapauth = sssdldapauth.cli:root

sssdldapauth/cli.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
3+
import click
4+
5+
import sssdldapauth
6+
7+
8+
@click.group()
9+
def root():
10+
pass
11+
12+
13+
@root.command()
14+
@click.argument("token")
15+
def deobfuscate(token):
16+
try:
17+
password = sssdldapauth.deobfuscate(token)
18+
except Exception:
19+
click.echo("unable to deobfuscate token", err=True)
20+
sys.exit(1)
21+
22+
click.echo(password)

tests/test_cli.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pytest
2+
from click.testing import CliRunner
3+
4+
from sssdldapauth import cli
5+
6+
OBFUSCATED = (
7+
"AAAQABagVAjf9KgUyIxTw3A+HUfbig7N1+L0qtY4xAULt2GY"
8+
"HFc1B3CBWGAE9ArooklBkpxQtROiyCGDQH+VzLHYmiIAAQID"
9+
)
10+
DEOBFUSCATED = "Passw0rd"
11+
12+
13+
@pytest.fixture()
14+
def runner():
15+
return CliRunner(mix_stderr=False)
16+
17+
18+
def test_valid(runner):
19+
result = runner.invoke(cli.root, ["deobfuscate", OBFUSCATED])
20+
21+
assert result.exit_code == 0
22+
assert result.output == f"{DEOBFUSCATED}\n"
23+
24+
25+
def test_invalid(runner):
26+
result = runner.invoke(cli.root, ["deobfuscate", "invalid"])
27+
28+
assert result.exit_code == 1
29+
assert result.output == ""
30+
assert result.stderr == "unable to deobfuscate token\n"

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
envlist = py36,py37,py38,py39,py310
33

44
[testenv]
5-
deps = pytest
5+
deps =
6+
click
7+
cryptography
8+
pytest
69
commands = pytest {posargs}

0 commit comments

Comments
 (0)