pyntcli 0.1.47__py3-none-any.whl → 0.1.48__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/build/lib/pyntcli/__init__.py +1 -0
- build/lib/build/lib/pyntcli/main.py +74 -0
- build/lib/build/lib/tests/auth/test_login.py +96 -0
- build/lib/build/lib/tests/conftest.py +24 -0
- build/lib/build/lib/tests/store/test_cred_store.py +11 -0
- build/lib/pyntcli/__init__.py +1 -0
- build/lib/pyntcli/main.py +74 -0
- build/lib/tests/auth/test_login.py +96 -0
- build/lib/tests/conftest.py +24 -0
- build/lib/tests/store/test_cred_store.py +11 -0
- pyntcli/__init__.py +1 -1
- pyntcli/auth/login.py +3 -0
- pyntcli/commands/postman.py +4 -0
- pyntcli/commands/root.py +1 -0
- pyntcli/pynt_docker/pynt_container.py +10 -2
- {pyntcli-0.1.47.dist-info → pyntcli-0.1.48.dist-info}/METADATA +1 -1
- pyntcli-0.1.48.dist-info/RECORD +127 -0
- {pyntcli-0.1.47.dist-info → pyntcli-0.1.48.dist-info}/top_level.txt +1 -0
- pyntcli-0.1.47.dist-info/RECORD +0 -37
- {pyntcli-0.1.47.dist-info → pyntcli-0.1.48.dist-info}/WHEEL +0 -0
- {pyntcli-0.1.47.dist-info → pyntcli-0.1.48.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from sys import argv, exit
|
|
2
|
+
import signal
|
|
3
|
+
|
|
4
|
+
from pyntcli.commands import pynt_cmd
|
|
5
|
+
from pyntcli.pynt_docker import pynt_container
|
|
6
|
+
from pyntcli.ui import ui_thread
|
|
7
|
+
from pyntcli.ui import pynt_errors
|
|
8
|
+
from pyntcli.auth import login
|
|
9
|
+
from pyntcli.analytics import send as analytics
|
|
10
|
+
from requests.exceptions import SSLError
|
|
11
|
+
from pyntcli.transport.pynt_requests import InvalidPathException, InvalidCertFormat
|
|
12
|
+
from pyntcli.commands.util import HtmlReportNotCreatedException
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
def signal_handler(signal_number, frame):
|
|
16
|
+
ui_thread.print(ui_thread.PrinterText("Exiting..."))
|
|
17
|
+
|
|
18
|
+
analytics.stop()
|
|
19
|
+
pynt_container.PyntContainerRegistery.instance().stop_all_containers()
|
|
20
|
+
ui_thread.stop()
|
|
21
|
+
|
|
22
|
+
exit(0)
|
|
23
|
+
|
|
24
|
+
def check_for_dependecies():
|
|
25
|
+
pynt_container.get_docker_type()
|
|
26
|
+
|
|
27
|
+
def print_header():
|
|
28
|
+
ui_thread.print(ui_thread.PrinterText(*ui_thread.pynt_header()) \
|
|
29
|
+
.with_line(*ui_thread.pynt_version()) \
|
|
30
|
+
.with_line(""))
|
|
31
|
+
def start_analytics():
|
|
32
|
+
user_id = login.user_id()
|
|
33
|
+
if user_id:
|
|
34
|
+
analytics.set_user_id(user_id)
|
|
35
|
+
|
|
36
|
+
def main():
|
|
37
|
+
print_header()
|
|
38
|
+
try:
|
|
39
|
+
start_analytics()
|
|
40
|
+
check_for_dependecies()
|
|
41
|
+
signal.signal(signal.SIGINT, signal_handler)
|
|
42
|
+
cli = pynt_cmd.PyntCommand()
|
|
43
|
+
cli.run_cmd(cli.parse_args(argv[1:]))
|
|
44
|
+
analytics.stop()
|
|
45
|
+
except pynt_cmd.PyntCommandException:
|
|
46
|
+
pynt_cmd.root.usage()
|
|
47
|
+
except pynt_container.DockerNotAvailableException:
|
|
48
|
+
ui_thread.print(ui_thread.PrinterText("Docker was unavailable, please make sure docker is installed and running.", ui_thread.PrinterText.WARNING))
|
|
49
|
+
analytics.emit(analytics.ERROR, {"error": "docker unavailable"})
|
|
50
|
+
except SSLError:
|
|
51
|
+
ui_thread.print(ui_thread.PrinterText("We encountered SSL issues and could not proceed, this may be the cause of a VPN or a Firewall in place.", ui_thread.PrinterText.WARNING))
|
|
52
|
+
except login.Timeout:
|
|
53
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to incomplete registration, please try again.", ui_thread.PrinterText.WARNING))
|
|
54
|
+
analytics.emit(analytics.ERROR, {"error": "login timeout"})
|
|
55
|
+
except login.InvalidTokenInEnvVarsException:
|
|
56
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to malformed credentials provided in env vars.", ui_thread.PrinterText.WARNING))
|
|
57
|
+
analytics.emit(analytics.ERROR, {"error": "invalid pynt cli credentials in env vars"})
|
|
58
|
+
except pynt_container.ImageUnavailableException:
|
|
59
|
+
analytics.emit(analytics.ERROR,{"error": "Couldnt pull pynt image and no local image found"})
|
|
60
|
+
pynt_errors.unexpected_error()
|
|
61
|
+
except HtmlReportNotCreatedException:
|
|
62
|
+
analytics.emit(analytics.ERROR,{"error": "Html report was not created"})
|
|
63
|
+
pynt_errors.unexpected_error()
|
|
64
|
+
except InvalidPathException as e:
|
|
65
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to invalid host-CA path: {}".format(e), ui_thread.PrinterText.WARNING))
|
|
66
|
+
analytics.emit(analytics.ERROR,{"error": "Host CA path provided was invalid"})
|
|
67
|
+
except InvalidCertFormat as e:
|
|
68
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to invalid host-CA. Please provide a file in PEM format: {}".format(e), ui_thread.PrinterText.WARNING))
|
|
69
|
+
analytics.emit(analytics.ERROR,{"error": "Host CA provided was not in valid pem format"})
|
|
70
|
+
finally:
|
|
71
|
+
ui_thread.stop()
|
|
72
|
+
|
|
73
|
+
if __name__ == "__main__":
|
|
74
|
+
main()
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from urllib.parse import urlparse
|
|
2
|
+
import json
|
|
3
|
+
from _pytest.monkeypatch import monkeypatch
|
|
4
|
+
import pytest
|
|
5
|
+
import requests
|
|
6
|
+
import requests_mock
|
|
7
|
+
import datetime
|
|
8
|
+
import jwt
|
|
9
|
+
import os
|
|
10
|
+
from cryptography.hazmat.primitives.asymmetric import rsa
|
|
11
|
+
from cryptography.hazmat.primitives import serialization
|
|
12
|
+
|
|
13
|
+
from pyntcli.auth.login import Login, Timeout, InvalidTokenInEnvVarsException, is_jwt_expired, should_login, PYNT_CREDENTIALS
|
|
14
|
+
from pyntcli.store import CredStore
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestLogin():
|
|
18
|
+
@pytest.fixture
|
|
19
|
+
def mock_webbrowser(self, mocker):
|
|
20
|
+
try:
|
|
21
|
+
mocker.patch("webbrowser.open", return_value=None)
|
|
22
|
+
yield
|
|
23
|
+
finally:
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
def get_request_url_parameters(self, req: requests.PreparedRequest) :
|
|
27
|
+
u = req.url
|
|
28
|
+
parsed_url = urlparse(u)
|
|
29
|
+
return parsed_url.query
|
|
30
|
+
|
|
31
|
+
def poll_matcher(self, request: requests.PreparedRequest):
|
|
32
|
+
assert "request_id" in self.get_request_url_parameters(request)
|
|
33
|
+
|
|
34
|
+
resp = requests.Response()
|
|
35
|
+
self.login_request_cnt += 1
|
|
36
|
+
if self.login_request_cnt < 2:
|
|
37
|
+
resp.status_code = 404
|
|
38
|
+
return resp
|
|
39
|
+
|
|
40
|
+
resp.status_code = 200
|
|
41
|
+
resp._content = json.dumps({"token": "testToken"}).encode()
|
|
42
|
+
return resp
|
|
43
|
+
|
|
44
|
+
def test_login(self, mock_webbrowser, mock_sleep, mock_expanduser):
|
|
45
|
+
l = Login()
|
|
46
|
+
self.login_request_cnt = 0
|
|
47
|
+
with requests_mock.mock() as m:
|
|
48
|
+
m.add_matcher(self.poll_matcher)
|
|
49
|
+
l.login()
|
|
50
|
+
|
|
51
|
+
assert self.login_request_cnt == 2
|
|
52
|
+
c = CredStore()
|
|
53
|
+
assert c.get("token") == {"token": "testToken"}
|
|
54
|
+
|
|
55
|
+
def test_login_timeout(self, mock_webbrowser, mock_sleep, mock_expanduser):
|
|
56
|
+
l = Login()
|
|
57
|
+
l.login_wait_period = 0
|
|
58
|
+
self.login_request_cnt = 0
|
|
59
|
+
with pytest.raises(Timeout):
|
|
60
|
+
with requests_mock.mock() as m:
|
|
61
|
+
m.add_matcher(self.poll_matcher)
|
|
62
|
+
l.get_token_using_request_id("some_id")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_is_jwt_expired(self):
|
|
66
|
+
|
|
67
|
+
private_key = rsa.generate_private_key(
|
|
68
|
+
public_exponent=65537,
|
|
69
|
+
key_size=2048
|
|
70
|
+
).private_bytes(encoding=serialization.Encoding.PEM,
|
|
71
|
+
format=serialization.PrivateFormat.PKCS8,
|
|
72
|
+
encryption_algorithm=serialization.NoEncryption())
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
token_data = {
|
|
76
|
+
"exp": int((datetime.datetime.now() - datetime.timedelta(days=1)).timestamp())
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
token = jwt.encode(token_data, private_key.decode(), algorithm="RS256").decode("utf-8")
|
|
80
|
+
assert is_jwt_expired(token) == True
|
|
81
|
+
|
|
82
|
+
token_data = {
|
|
83
|
+
"exp": int((datetime.datetime.now() + datetime.timedelta(days=1)).timestamp())
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
token = jwt.encode(token_data, private_key.decode(), algorithm="RS256").decode("utf-8")
|
|
87
|
+
assert is_jwt_expired(token) == False
|
|
88
|
+
|
|
89
|
+
def test_login_using_env_vars(self, mocker, mock_expanduser):
|
|
90
|
+
creds = json.dumps({"token": {"refresh_token": "some data"}})
|
|
91
|
+
mocker.patch.dict(os.environ, {PYNT_CREDENTIALS: creds})
|
|
92
|
+
assert should_login() == False
|
|
93
|
+
|
|
94
|
+
os.environ[PYNT_CREDENTIALS] = "some bad credentials"
|
|
95
|
+
with pytest.raises(InvalidTokenInEnvVarsException):
|
|
96
|
+
should_login()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import tempfile
|
|
2
|
+
import pytest
|
|
3
|
+
import shutil
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
sys.path.append("../")
|
|
7
|
+
|
|
8
|
+
@pytest.fixture
|
|
9
|
+
def mock_expanduser( mocker):
|
|
10
|
+
dir = tempfile.mkdtemp()
|
|
11
|
+
try:
|
|
12
|
+
mocker.patch("os.path.expanduser", return_value=dir)
|
|
13
|
+
yield
|
|
14
|
+
finally:
|
|
15
|
+
shutil.rmtree(dir)
|
|
16
|
+
|
|
17
|
+
@pytest.fixture
|
|
18
|
+
def mock_sleep( mocker):
|
|
19
|
+
try:
|
|
20
|
+
mocker.patch("time.sleep", return_value=None)
|
|
21
|
+
yield
|
|
22
|
+
finally:
|
|
23
|
+
pass
|
|
24
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.48"
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from sys import argv, exit
|
|
2
|
+
import signal
|
|
3
|
+
|
|
4
|
+
from pyntcli.commands import pynt_cmd
|
|
5
|
+
from pyntcli.pynt_docker import pynt_container
|
|
6
|
+
from pyntcli.ui import ui_thread
|
|
7
|
+
from pyntcli.ui import pynt_errors
|
|
8
|
+
from pyntcli.auth import login
|
|
9
|
+
from pyntcli.analytics import send as analytics
|
|
10
|
+
from requests.exceptions import SSLError
|
|
11
|
+
from pyntcli.transport.pynt_requests import InvalidPathException, InvalidCertFormat
|
|
12
|
+
from pyntcli.commands.util import HtmlReportNotCreatedException
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
def signal_handler(signal_number, frame):
|
|
16
|
+
ui_thread.print(ui_thread.PrinterText("Exiting..."))
|
|
17
|
+
|
|
18
|
+
analytics.stop()
|
|
19
|
+
pynt_container.PyntContainerRegistery.instance().stop_all_containers()
|
|
20
|
+
ui_thread.stop()
|
|
21
|
+
|
|
22
|
+
exit(0)
|
|
23
|
+
|
|
24
|
+
def check_for_dependecies():
|
|
25
|
+
pynt_container.get_docker_type()
|
|
26
|
+
|
|
27
|
+
def print_header():
|
|
28
|
+
ui_thread.print(ui_thread.PrinterText(*ui_thread.pynt_header()) \
|
|
29
|
+
.with_line(*ui_thread.pynt_version()) \
|
|
30
|
+
.with_line(""))
|
|
31
|
+
def start_analytics():
|
|
32
|
+
user_id = login.user_id()
|
|
33
|
+
if user_id:
|
|
34
|
+
analytics.set_user_id(user_id)
|
|
35
|
+
|
|
36
|
+
def main():
|
|
37
|
+
print_header()
|
|
38
|
+
try:
|
|
39
|
+
start_analytics()
|
|
40
|
+
check_for_dependecies()
|
|
41
|
+
signal.signal(signal.SIGINT, signal_handler)
|
|
42
|
+
cli = pynt_cmd.PyntCommand()
|
|
43
|
+
cli.run_cmd(cli.parse_args(argv[1:]))
|
|
44
|
+
analytics.stop()
|
|
45
|
+
except pynt_cmd.PyntCommandException:
|
|
46
|
+
pynt_cmd.root.usage()
|
|
47
|
+
except pynt_container.DockerNotAvailableException:
|
|
48
|
+
ui_thread.print(ui_thread.PrinterText("Docker was unavailable, please make sure docker is installed and running.", ui_thread.PrinterText.WARNING))
|
|
49
|
+
analytics.emit(analytics.ERROR, {"error": "docker unavailable"})
|
|
50
|
+
except SSLError:
|
|
51
|
+
ui_thread.print(ui_thread.PrinterText("We encountered SSL issues and could not proceed, this may be the cause of a VPN or a Firewall in place.", ui_thread.PrinterText.WARNING))
|
|
52
|
+
except login.Timeout:
|
|
53
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to incomplete registration, please try again.", ui_thread.PrinterText.WARNING))
|
|
54
|
+
analytics.emit(analytics.ERROR, {"error": "login timeout"})
|
|
55
|
+
except login.InvalidTokenInEnvVarsException:
|
|
56
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to malformed credentials provided in env vars.", ui_thread.PrinterText.WARNING))
|
|
57
|
+
analytics.emit(analytics.ERROR, {"error": "invalid pynt cli credentials in env vars"})
|
|
58
|
+
except pynt_container.ImageUnavailableException:
|
|
59
|
+
analytics.emit(analytics.ERROR,{"error": "Couldnt pull pynt image and no local image found"})
|
|
60
|
+
pynt_errors.unexpected_error()
|
|
61
|
+
except HtmlReportNotCreatedException:
|
|
62
|
+
analytics.emit(analytics.ERROR,{"error": "Html report was not created"})
|
|
63
|
+
pynt_errors.unexpected_error()
|
|
64
|
+
except InvalidPathException as e:
|
|
65
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to invalid host-CA path: {}".format(e), ui_thread.PrinterText.WARNING))
|
|
66
|
+
analytics.emit(analytics.ERROR,{"error": "Host CA path provided was invalid"})
|
|
67
|
+
except InvalidCertFormat as e:
|
|
68
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to invalid host-CA. Please provide a file in PEM format: {}".format(e), ui_thread.PrinterText.WARNING))
|
|
69
|
+
analytics.emit(analytics.ERROR,{"error": "Host CA provided was not in valid pem format"})
|
|
70
|
+
finally:
|
|
71
|
+
ui_thread.stop()
|
|
72
|
+
|
|
73
|
+
if __name__ == "__main__":
|
|
74
|
+
main()
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from urllib.parse import urlparse
|
|
2
|
+
import json
|
|
3
|
+
from _pytest.monkeypatch import monkeypatch
|
|
4
|
+
import pytest
|
|
5
|
+
import requests
|
|
6
|
+
import requests_mock
|
|
7
|
+
import datetime
|
|
8
|
+
import jwt
|
|
9
|
+
import os
|
|
10
|
+
from cryptography.hazmat.primitives.asymmetric import rsa
|
|
11
|
+
from cryptography.hazmat.primitives import serialization
|
|
12
|
+
|
|
13
|
+
from pyntcli.auth.login import Login, Timeout, InvalidTokenInEnvVarsException, is_jwt_expired, should_login, PYNT_CREDENTIALS
|
|
14
|
+
from pyntcli.store import CredStore
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestLogin():
|
|
18
|
+
@pytest.fixture
|
|
19
|
+
def mock_webbrowser(self, mocker):
|
|
20
|
+
try:
|
|
21
|
+
mocker.patch("webbrowser.open", return_value=None)
|
|
22
|
+
yield
|
|
23
|
+
finally:
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
def get_request_url_parameters(self, req: requests.PreparedRequest) :
|
|
27
|
+
u = req.url
|
|
28
|
+
parsed_url = urlparse(u)
|
|
29
|
+
return parsed_url.query
|
|
30
|
+
|
|
31
|
+
def poll_matcher(self, request: requests.PreparedRequest):
|
|
32
|
+
assert "request_id" in self.get_request_url_parameters(request)
|
|
33
|
+
|
|
34
|
+
resp = requests.Response()
|
|
35
|
+
self.login_request_cnt += 1
|
|
36
|
+
if self.login_request_cnt < 2:
|
|
37
|
+
resp.status_code = 404
|
|
38
|
+
return resp
|
|
39
|
+
|
|
40
|
+
resp.status_code = 200
|
|
41
|
+
resp._content = json.dumps({"token": "testToken"}).encode()
|
|
42
|
+
return resp
|
|
43
|
+
|
|
44
|
+
def test_login(self, mock_webbrowser, mock_sleep, mock_expanduser):
|
|
45
|
+
l = Login()
|
|
46
|
+
self.login_request_cnt = 0
|
|
47
|
+
with requests_mock.mock() as m:
|
|
48
|
+
m.add_matcher(self.poll_matcher)
|
|
49
|
+
l.login()
|
|
50
|
+
|
|
51
|
+
assert self.login_request_cnt == 2
|
|
52
|
+
c = CredStore()
|
|
53
|
+
assert c.get("token") == {"token": "testToken"}
|
|
54
|
+
|
|
55
|
+
def test_login_timeout(self, mock_webbrowser, mock_sleep, mock_expanduser):
|
|
56
|
+
l = Login()
|
|
57
|
+
l.login_wait_period = 0
|
|
58
|
+
self.login_request_cnt = 0
|
|
59
|
+
with pytest.raises(Timeout):
|
|
60
|
+
with requests_mock.mock() as m:
|
|
61
|
+
m.add_matcher(self.poll_matcher)
|
|
62
|
+
l.get_token_using_request_id("some_id")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_is_jwt_expired(self):
|
|
66
|
+
|
|
67
|
+
private_key = rsa.generate_private_key(
|
|
68
|
+
public_exponent=65537,
|
|
69
|
+
key_size=2048
|
|
70
|
+
).private_bytes(encoding=serialization.Encoding.PEM,
|
|
71
|
+
format=serialization.PrivateFormat.PKCS8,
|
|
72
|
+
encryption_algorithm=serialization.NoEncryption())
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
token_data = {
|
|
76
|
+
"exp": int((datetime.datetime.now() - datetime.timedelta(days=1)).timestamp())
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
token = jwt.encode(token_data, private_key.decode(), algorithm="RS256").decode("utf-8")
|
|
80
|
+
assert is_jwt_expired(token) == True
|
|
81
|
+
|
|
82
|
+
token_data = {
|
|
83
|
+
"exp": int((datetime.datetime.now() + datetime.timedelta(days=1)).timestamp())
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
token = jwt.encode(token_data, private_key.decode(), algorithm="RS256").decode("utf-8")
|
|
87
|
+
assert is_jwt_expired(token) == False
|
|
88
|
+
|
|
89
|
+
def test_login_using_env_vars(self, mocker, mock_expanduser):
|
|
90
|
+
creds = json.dumps({"token": {"refresh_token": "some data"}})
|
|
91
|
+
mocker.patch.dict(os.environ, {PYNT_CREDENTIALS: creds})
|
|
92
|
+
assert should_login() == False
|
|
93
|
+
|
|
94
|
+
os.environ[PYNT_CREDENTIALS] = "some bad credentials"
|
|
95
|
+
with pytest.raises(InvalidTokenInEnvVarsException):
|
|
96
|
+
should_login()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import tempfile
|
|
2
|
+
import pytest
|
|
3
|
+
import shutil
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
sys.path.append("../")
|
|
7
|
+
|
|
8
|
+
@pytest.fixture
|
|
9
|
+
def mock_expanduser( mocker):
|
|
10
|
+
dir = tempfile.mkdtemp()
|
|
11
|
+
try:
|
|
12
|
+
mocker.patch("os.path.expanduser", return_value=dir)
|
|
13
|
+
yield
|
|
14
|
+
finally:
|
|
15
|
+
shutil.rmtree(dir)
|
|
16
|
+
|
|
17
|
+
@pytest.fixture
|
|
18
|
+
def mock_sleep( mocker):
|
|
19
|
+
try:
|
|
20
|
+
mocker.patch("time.sleep", return_value=None)
|
|
21
|
+
yield
|
|
22
|
+
finally:
|
|
23
|
+
pass
|
|
24
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.48"
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from sys import argv, exit
|
|
2
|
+
import signal
|
|
3
|
+
|
|
4
|
+
from pyntcli.commands import pynt_cmd
|
|
5
|
+
from pyntcli.pynt_docker import pynt_container
|
|
6
|
+
from pyntcli.ui import ui_thread
|
|
7
|
+
from pyntcli.ui import pynt_errors
|
|
8
|
+
from pyntcli.auth import login
|
|
9
|
+
from pyntcli.analytics import send as analytics
|
|
10
|
+
from requests.exceptions import SSLError
|
|
11
|
+
from pyntcli.transport.pynt_requests import InvalidPathException, InvalidCertFormat
|
|
12
|
+
from pyntcli.commands.util import HtmlReportNotCreatedException
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
def signal_handler(signal_number, frame):
|
|
16
|
+
ui_thread.print(ui_thread.PrinterText("Exiting..."))
|
|
17
|
+
|
|
18
|
+
analytics.stop()
|
|
19
|
+
pynt_container.PyntContainerRegistery.instance().stop_all_containers()
|
|
20
|
+
ui_thread.stop()
|
|
21
|
+
|
|
22
|
+
exit(0)
|
|
23
|
+
|
|
24
|
+
def check_for_dependecies():
|
|
25
|
+
pynt_container.get_docker_type()
|
|
26
|
+
|
|
27
|
+
def print_header():
|
|
28
|
+
ui_thread.print(ui_thread.PrinterText(*ui_thread.pynt_header()) \
|
|
29
|
+
.with_line(*ui_thread.pynt_version()) \
|
|
30
|
+
.with_line(""))
|
|
31
|
+
def start_analytics():
|
|
32
|
+
user_id = login.user_id()
|
|
33
|
+
if user_id:
|
|
34
|
+
analytics.set_user_id(user_id)
|
|
35
|
+
|
|
36
|
+
def main():
|
|
37
|
+
print_header()
|
|
38
|
+
try:
|
|
39
|
+
start_analytics()
|
|
40
|
+
check_for_dependecies()
|
|
41
|
+
signal.signal(signal.SIGINT, signal_handler)
|
|
42
|
+
cli = pynt_cmd.PyntCommand()
|
|
43
|
+
cli.run_cmd(cli.parse_args(argv[1:]))
|
|
44
|
+
analytics.stop()
|
|
45
|
+
except pynt_cmd.PyntCommandException:
|
|
46
|
+
pynt_cmd.root.usage()
|
|
47
|
+
except pynt_container.DockerNotAvailableException:
|
|
48
|
+
ui_thread.print(ui_thread.PrinterText("Docker was unavailable, please make sure docker is installed and running.", ui_thread.PrinterText.WARNING))
|
|
49
|
+
analytics.emit(analytics.ERROR, {"error": "docker unavailable"})
|
|
50
|
+
except SSLError:
|
|
51
|
+
ui_thread.print(ui_thread.PrinterText("We encountered SSL issues and could not proceed, this may be the cause of a VPN or a Firewall in place.", ui_thread.PrinterText.WARNING))
|
|
52
|
+
except login.Timeout:
|
|
53
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to incomplete registration, please try again.", ui_thread.PrinterText.WARNING))
|
|
54
|
+
analytics.emit(analytics.ERROR, {"error": "login timeout"})
|
|
55
|
+
except login.InvalidTokenInEnvVarsException:
|
|
56
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to malformed credentials provided in env vars.", ui_thread.PrinterText.WARNING))
|
|
57
|
+
analytics.emit(analytics.ERROR, {"error": "invalid pynt cli credentials in env vars"})
|
|
58
|
+
except pynt_container.ImageUnavailableException:
|
|
59
|
+
analytics.emit(analytics.ERROR,{"error": "Couldnt pull pynt image and no local image found"})
|
|
60
|
+
pynt_errors.unexpected_error()
|
|
61
|
+
except HtmlReportNotCreatedException:
|
|
62
|
+
analytics.emit(analytics.ERROR,{"error": "Html report was not created"})
|
|
63
|
+
pynt_errors.unexpected_error()
|
|
64
|
+
except InvalidPathException as e:
|
|
65
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to invalid host-CA path: {}".format(e), ui_thread.PrinterText.WARNING))
|
|
66
|
+
analytics.emit(analytics.ERROR,{"error": "Host CA path provided was invalid"})
|
|
67
|
+
except InvalidCertFormat as e:
|
|
68
|
+
ui_thread.print(ui_thread.PrinterText("Pynt CLI exited due to invalid host-CA. Please provide a file in PEM format: {}".format(e), ui_thread.PrinterText.WARNING))
|
|
69
|
+
analytics.emit(analytics.ERROR,{"error": "Host CA provided was not in valid pem format"})
|
|
70
|
+
finally:
|
|
71
|
+
ui_thread.stop()
|
|
72
|
+
|
|
73
|
+
if __name__ == "__main__":
|
|
74
|
+
main()
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from urllib.parse import urlparse
|
|
2
|
+
import json
|
|
3
|
+
from _pytest.monkeypatch import monkeypatch
|
|
4
|
+
import pytest
|
|
5
|
+
import requests
|
|
6
|
+
import requests_mock
|
|
7
|
+
import datetime
|
|
8
|
+
import jwt
|
|
9
|
+
import os
|
|
10
|
+
from cryptography.hazmat.primitives.asymmetric import rsa
|
|
11
|
+
from cryptography.hazmat.primitives import serialization
|
|
12
|
+
|
|
13
|
+
from pyntcli.auth.login import Login, Timeout, InvalidTokenInEnvVarsException, is_jwt_expired, should_login, PYNT_CREDENTIALS
|
|
14
|
+
from pyntcli.store import CredStore
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestLogin():
|
|
18
|
+
@pytest.fixture
|
|
19
|
+
def mock_webbrowser(self, mocker):
|
|
20
|
+
try:
|
|
21
|
+
mocker.patch("webbrowser.open", return_value=None)
|
|
22
|
+
yield
|
|
23
|
+
finally:
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
def get_request_url_parameters(self, req: requests.PreparedRequest) :
|
|
27
|
+
u = req.url
|
|
28
|
+
parsed_url = urlparse(u)
|
|
29
|
+
return parsed_url.query
|
|
30
|
+
|
|
31
|
+
def poll_matcher(self, request: requests.PreparedRequest):
|
|
32
|
+
assert "request_id" in self.get_request_url_parameters(request)
|
|
33
|
+
|
|
34
|
+
resp = requests.Response()
|
|
35
|
+
self.login_request_cnt += 1
|
|
36
|
+
if self.login_request_cnt < 2:
|
|
37
|
+
resp.status_code = 404
|
|
38
|
+
return resp
|
|
39
|
+
|
|
40
|
+
resp.status_code = 200
|
|
41
|
+
resp._content = json.dumps({"token": "testToken"}).encode()
|
|
42
|
+
return resp
|
|
43
|
+
|
|
44
|
+
def test_login(self, mock_webbrowser, mock_sleep, mock_expanduser):
|
|
45
|
+
l = Login()
|
|
46
|
+
self.login_request_cnt = 0
|
|
47
|
+
with requests_mock.mock() as m:
|
|
48
|
+
m.add_matcher(self.poll_matcher)
|
|
49
|
+
l.login()
|
|
50
|
+
|
|
51
|
+
assert self.login_request_cnt == 2
|
|
52
|
+
c = CredStore()
|
|
53
|
+
assert c.get("token") == {"token": "testToken"}
|
|
54
|
+
|
|
55
|
+
def test_login_timeout(self, mock_webbrowser, mock_sleep, mock_expanduser):
|
|
56
|
+
l = Login()
|
|
57
|
+
l.login_wait_period = 0
|
|
58
|
+
self.login_request_cnt = 0
|
|
59
|
+
with pytest.raises(Timeout):
|
|
60
|
+
with requests_mock.mock() as m:
|
|
61
|
+
m.add_matcher(self.poll_matcher)
|
|
62
|
+
l.get_token_using_request_id("some_id")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_is_jwt_expired(self):
|
|
66
|
+
|
|
67
|
+
private_key = rsa.generate_private_key(
|
|
68
|
+
public_exponent=65537,
|
|
69
|
+
key_size=2048
|
|
70
|
+
).private_bytes(encoding=serialization.Encoding.PEM,
|
|
71
|
+
format=serialization.PrivateFormat.PKCS8,
|
|
72
|
+
encryption_algorithm=serialization.NoEncryption())
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
token_data = {
|
|
76
|
+
"exp": int((datetime.datetime.now() - datetime.timedelta(days=1)).timestamp())
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
token = jwt.encode(token_data, private_key.decode(), algorithm="RS256").decode("utf-8")
|
|
80
|
+
assert is_jwt_expired(token) == True
|
|
81
|
+
|
|
82
|
+
token_data = {
|
|
83
|
+
"exp": int((datetime.datetime.now() + datetime.timedelta(days=1)).timestamp())
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
token = jwt.encode(token_data, private_key.decode(), algorithm="RS256").decode("utf-8")
|
|
87
|
+
assert is_jwt_expired(token) == False
|
|
88
|
+
|
|
89
|
+
def test_login_using_env_vars(self, mocker, mock_expanduser):
|
|
90
|
+
creds = json.dumps({"token": {"refresh_token": "some data"}})
|
|
91
|
+
mocker.patch.dict(os.environ, {PYNT_CREDENTIALS: creds})
|
|
92
|
+
assert should_login() == False
|
|
93
|
+
|
|
94
|
+
os.environ[PYNT_CREDENTIALS] = "some bad credentials"
|
|
95
|
+
with pytest.raises(InvalidTokenInEnvVarsException):
|
|
96
|
+
should_login()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import tempfile
|
|
2
|
+
import pytest
|
|
3
|
+
import shutil
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
sys.path.append("../")
|
|
7
|
+
|
|
8
|
+
@pytest.fixture
|
|
9
|
+
def mock_expanduser( mocker):
|
|
10
|
+
dir = tempfile.mkdtemp()
|
|
11
|
+
try:
|
|
12
|
+
mocker.patch("os.path.expanduser", return_value=dir)
|
|
13
|
+
yield
|
|
14
|
+
finally:
|
|
15
|
+
shutil.rmtree(dir)
|
|
16
|
+
|
|
17
|
+
@pytest.fixture
|
|
18
|
+
def mock_sleep( mocker):
|
|
19
|
+
try:
|
|
20
|
+
mocker.patch("time.sleep", return_value=None)
|
|
21
|
+
yield
|
|
22
|
+
finally:
|
|
23
|
+
pass
|
|
24
|
+
|
pyntcli/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.1.
|
|
1
|
+
__version__ = "0.1.48"
|
pyntcli/auth/login.py
CHANGED
|
@@ -21,6 +21,7 @@ class InvalidTokenInEnvVarsException(LoginException):
|
|
|
21
21
|
pass
|
|
22
22
|
|
|
23
23
|
PYNT_CREDENTIALS = "PYNT_CREDENTIALS"
|
|
24
|
+
PYNT_SAAS = "PYNT_SAAS_URL"
|
|
24
25
|
|
|
25
26
|
class Login():
|
|
26
27
|
def __init__(self) -> None:
|
|
@@ -59,6 +60,8 @@ class Login():
|
|
|
59
60
|
|
|
60
61
|
|
|
61
62
|
def refresh_request(refresh_token):
|
|
63
|
+
if os.environ.get(PYNT_SAAS):
|
|
64
|
+
return pynt_requests.post(os.environ[PYNT_SAAS] + "/auth/refresh", json={"refresh_token": refresh_token})
|
|
62
65
|
return pynt_requests.post("https://auth.pynt.io/default/refresh", json={"refresh_token": refresh_token})
|
|
63
66
|
|
|
64
67
|
def refresh_token():
|
pyntcli/commands/postman.py
CHANGED
|
@@ -32,6 +32,10 @@ class PostmanSubCommand(sub_command.PyntSubCommand):
|
|
|
32
32
|
return postman_cmd
|
|
33
33
|
|
|
34
34
|
def run_cmd(self, args: argparse.Namespace):
|
|
35
|
+
if "application_id" in args and args.application_id:
|
|
36
|
+
ui_thread.print("application-id is not supported in postman integration, use the request body in the start scan request")
|
|
37
|
+
args.application_id = ""
|
|
38
|
+
|
|
35
39
|
container = pynt_container.get_container_with_arguments(args ,pynt_container.PyntDockerPort("5001", args.port, name="--port"))
|
|
36
40
|
|
|
37
41
|
if util.is_port_in_use(args.port):
|
pyntcli/commands/root.py
CHANGED
|
@@ -37,6 +37,7 @@ class BaseCommand():
|
|
|
37
37
|
parser.add_argument("--insecure", default=False, required=False, action='store_true',help="use when target uses self signed certificates")
|
|
38
38
|
parser.add_argument("--dev-flags", type=str,default="", help=argparse.SUPPRESS)
|
|
39
39
|
parser.add_argument("--host-ca", type=str, default="")
|
|
40
|
+
parser.add_argument("--application-id", type=str, default="", required=False)
|
|
40
41
|
|
|
41
42
|
def get_subparser(self) -> argparse._SubParsersAction:
|
|
42
43
|
if self.subparser is None:
|