-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds necessary code to api.Client to have the client send authenticated requests if desired. This is enabled by default, but can be disabled by calling api.Client().logout() or by passing a flag to the constructor to disable it from the start. Also adds API login and logout tests. Also has the CLI client login to the server after configuring the host and port. This has the effect of all CLI tests being authenticated. Negative tests for unauthenticated qpc commands and logout tests for the CLI should be added at another time. Closes #93
- Loading branch information
Showing
10 changed files
with
155 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# coding=utf-8 | ||
"""Tests for Quipucords server authentication.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# coding=utf-8 | ||
"""Test that we can log in and out of the server. | ||
:caseautomation: automated | ||
:casecomponent: api | ||
:caseimportance: high | ||
:caselevel: integration | ||
:requirement: Sonar | ||
:testtype: functional | ||
:upstream: yes | ||
""" | ||
import pytest | ||
import requests | ||
|
||
from camayoc import api | ||
from camayoc.constants import QCS_SOURCE_PATH | ||
|
||
|
||
def test_login(): | ||
"""Test that we can login to the server. | ||
:id: 2eb55229-4e1e-4d35-ac4a-4f2424d37cf6 | ||
:description: Test that we can login to the server | ||
:steps: Send POST with username and password to the token endpoint | ||
:expectedresults: Receive an authorization token that we can then use | ||
to build our authentication headers and make authenticated requests. | ||
""" | ||
client = api.Client(authenticate=False) | ||
client.login() | ||
client.get(QCS_SOURCE_PATH) | ||
|
||
|
||
def test_logout(): | ||
"""Test that we can't access the server without a token. | ||
:id: ca51b2a0-1e33-491d-8bb2-5e81d135424d | ||
:description: Test that to the server | ||
:steps: | ||
1) Log into the server | ||
2) "Logout" of the server (delete our token) | ||
3) Try an access the server without our token | ||
:expectedresults: Our request missing an auth token is rejected. | ||
""" | ||
client = api.Client(authenticate=False) | ||
client.login() | ||
client.logout() | ||
with pytest.raises(requests.HTTPError): | ||
# now that we are logged out, we should get rejected | ||
client.get(QCS_SOURCE_PATH) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
camayoc\.tests\.qcs\.api\.v1\.authentication package | ||
==================================================== | ||
|
||
.. automodule:: camayoc.tests.qcs.api.v1.authentication | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Submodules | ||
---------- | ||
|
||
.. toctree:: | ||
|
||
camayoc.tests.qcs.api.v1.authentication.test_login | ||
|
7 changes: 7 additions & 0 deletions
7
docs/api/camayoc.tests.qcs.api.v1.authentication.test_login.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
camayoc\.tests\.qcs\.api\.v1\.authentication\.test\_login module | ||
================================================================ | ||
|
||
.. automodule:: camayoc.tests.qcs.api.v1.authentication.test_login | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters