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

3078 test unauthenticated requests rejected #3217

Merged
merged 2 commits into from
Apr 10, 2023

Conversation

mssalvatore
Copy link
Collaborator

@mssalvatore mssalvatore commented Apr 10, 2023

What does this PR do?

Add a blackbox test to verify API rejects unauthenticated requests.

Merge after #3216

PR Checklist

  • Have you added an explanation of what your changes do and why you'd like to include them?
  • Is the TravisCI build passing?
  • Was the CHANGELOG.md updated to reflect the changes?
  • Was the documentation framework updated to reflect the changes?
  • Have you checked that you haven't introduced any duplicate code?

Testing Checklist

  • Added relevant unit tests?
  • Do all unit tests pass?
  • Do all end-to-end tests pass
  • If applicable, add screenshots or log transcripts of the feature working

@mssalvatore mssalvatore marked this pull request as draft April 10, 2023 16:21
Comment on lines +329 to +345
def test_unauthenticated_user_cannot_access_API(island):
island_requests = MonkeyIslandRequests(island)

assert (
island_requests.post(AGENT_EVENTS_ENDPOINT, data=None).status_code
== HTTPStatus.UNAUTHORIZED
)
assert (
island_requests.post(AGENT_HEARTBEAT_ENDPOINT, data=None).status_code
== HTTPStatus.UNAUTHORIZED
)
assert island_requests.put(PUT_LOG_ENDPOINT, data=None).status_code == HTTPStatus.UNAUTHORIZED
assert island_requests.get(GET_AGENT_PLUGINS_ENDPOINT).status_code == HTTPStatus.UNAUTHORIZED
assert (
island_requests.get("/api/agent-plugins/plugin-type/plugin-name/manifest").status_code
== HTTPStatus.UNAUTHORIZED
)
assert island_requests.get(GET_AGENT_SIGNALS_ENDPOINT).status_code == HTTPStatus.UNAUTHORIZED
assert (
island_requests.post(GET_AGENTS_ENDPOINT, data=None).status_code == HTTPStatus.UNAUTHORIZED
)
assert island_requests.get(GET_AGENT_EVENTS_ENDPOINT).status_code == HTTPStatus.UNAUTHORIZED
assert island_requests.get(PUT_LOG_ENDPOINT).status_code == HTTPStatus.UNAUTHORIZED
assert (
island_requests.post(TERMINATE_AGENTS_ENDPOINT, data=None).status_code
== HTTPStatus.UNAUTHORIZED
)
Copy link
Contributor

@ilija-lazoroski ilija-lazoroski Apr 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long test. At least let's divide them by method: POST, GET, and PUT.

Copy link
Collaborator Author

@mssalvatore mssalvatore Apr 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an all around better approach would be to publish something like an OpenAPI spec and then redesign this test to programatically try all endpoints, but that's out of scope for this release.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking these up could result in a large number of login requests which is unnecessary. A whole lot of refactoring needs to happen in this file anyway. I say we just push it until later.

Copy link
Contributor

@ilija-lazoroski ilija-lazoroski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment

Base automatically changed from 3078-rate-limit-login to develop April 10, 2023 17:20
@mssalvatore mssalvatore force-pushed the 3078-test-unauthenticated-requests-rejected branch from bb68f97 to ea5323c Compare April 10, 2023 17:20
@mssalvatore mssalvatore marked this pull request as ready for review April 10, 2023 17:21
@mssalvatore mssalvatore merged commit 69e326b into develop Apr 10, 2023
@mssalvatore mssalvatore deleted the 3078-test-unauthenticated-requests-rejected branch April 10, 2023 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants