-
Notifications
You must be signed in to change notification settings - Fork 0
Add tests for authorization URL API #20
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| *** Settings *** | ||
| Resource resources/keywords.robot | ||
| Resource resources/variables.robot | ||
|
|
||
| Library OperatingSystem | ||
| Library BuiltIn | ||
| Library RequestsLibrary | ||
|
|
||
| Library resources.helpers | ||
| Library resources.projects.Projects | ||
| Library resources.providers.Providers | ||
| Library resources.ruletypes.Ruletypes | ||
| Library resources.profiles.Profiles | ||
| Library resources.minder_restapi_lib.MinderRestApiLib | ||
| Library resources.minderlib | ||
| Library resources.oauth_service.OAuthService | ||
|
|
||
| Suite Setup Set Rest Base URL From Config | ||
|
|
||
| Test Setup Default Setup | ||
| Test Teardown Default Teardown | ||
|
|
||
| *** Keywords *** | ||
| Default Setup | ||
| Set Project as Environment Variable with Test Name | ||
|
|
||
| Default Teardown | ||
| Remove Project Environment Variable for Test | ||
|
|
||
| *** Test Cases *** | ||
| Test Authorization URL API for GitHub App | ||
| [Documentation] Test that the authorization URL matches the GitHub App installation page | ||
| [Tags] OAuthService | ||
|
|
||
| When Client Gets Authorization Url github-app | ||
| Given Response Format Is Valid | ||
| Then URL Is Not Empty | ||
| And URL Is GitHub App Installation Page | ||
| And State Is Not Empty | ||
|
|
||
| Test Authorization URL API for GitHub OAuth | ||
| [Documentation] Test that the authorization URL matches the GitHub OAuth authorization URL | ||
| [Tags] OAuthService | ||
|
|
||
| When Client Gets Authorization Url github | ||
| Given Response Format Is Valid | ||
| Then URL Is Not Empty | ||
| And URL Is Authorization Code | ||
| And State Is Not Empty | ||
This file contains hidden or 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,110 @@ | ||
| import os | ||
| import re | ||
|
|
||
| from robot.api import logger | ||
| from robot.api.deco import keyword | ||
|
|
||
| from resources.errors import ConfigurationError, APIError | ||
| from resources.minder_restapi_lib import MinderRestApiLib | ||
|
|
||
| GITHUB_APP_PATTERN = r"https://github\.com/apps/[\w-]+/installations/new" | ||
| GITHUB_AUTHORIZATION_URL = r"https://github\.com/login/oauth/authorize?[\w-]+" | ||
|
|
||
|
|
||
| class OAuthService: | ||
| def __init__(self): | ||
| self.response = None | ||
|
|
||
| @keyword | ||
| def client_gets_authorization_url(self, provider_class): | ||
| """Gets the authorization URL for enrolling a new provider. | ||
|
|
||
| Returns: | ||
| dict: The JSON response from the API. | ||
|
|
||
| Raises: | ||
| ConfigurationError: If required configuration is missing. | ||
| APIError: If the API request fails. | ||
|
|
||
| """ | ||
| project = os.getenv("MINDER_PROJECT") | ||
| if not project: | ||
| raise ConfigurationError("MINDER_PROJECT environment variable is not set") | ||
|
|
||
| params = { | ||
| # "provider": provider, | ||
| "context.project": project, | ||
| "provider_class": provider_class | ||
| } | ||
|
|
||
| try: | ||
| rest_api = MinderRestApiLib() | ||
| self.response = rest_api.get_request('/auth/url', params=params) | ||
| except Exception as e: | ||
| raise APIError(f"API request failed: {str(e)}") | ||
|
|
||
| @keyword | ||
| def response_format_is_valid(self): | ||
| """ | ||
| Verifies the structure of the API response. | ||
|
|
||
| Args: | ||
| response (dict): The JSON response from the API. | ||
|
|
||
| Raises: | ||
| ValueError: If the response does not have the expected structure. | ||
| """ | ||
| if not isinstance(self.response, dict): | ||
| raise ValueError("Response should be a dictionary") | ||
|
|
||
| if "url" not in self.response: | ||
| raise ValueError("Response does not contain 'url' key") | ||
|
|
||
| if "state" not in self.response: | ||
| raise ValueError("Response does not contain 'state' key") | ||
|
|
||
| logger.info("Get ruletype by name response structure verified successfully") | ||
|
|
||
| @keyword | ||
| def url_is_not_empty(self): | ||
| """ | ||
| Verifies that the response contains a non-empty authorization URL. | ||
|
|
||
| Raises: | ||
| ValueError: If the URL field is empty. | ||
| """ | ||
| if self.response["url"] == "": | ||
| raise ValueError("URL should not be empty") | ||
|
|
||
| @keyword | ||
| def state_is_not_empty(self): | ||
| """ | ||
| Verifies that the response contains a non-empty state. | ||
|
|
||
| Raises: | ||
| ValueError: If the state field is empty. | ||
| """ | ||
| if self.response["state"] == "": | ||
| raise ValueError("State should not be empty") | ||
|
|
||
| @keyword | ||
| def url_is_github_app_installation_page(self): | ||
| """ | ||
| Verifies that the authorization URL is the GitHub App installation page. | ||
|
|
||
| Raises: | ||
| ValueError: If the URL does not match the expected pattern. | ||
| """ | ||
| if not re.match(GITHUB_APP_PATTERN, self.response["url"]): | ||
| raise ValueError("URL should match GitHub App installation page pattern") | ||
|
|
||
| @keyword | ||
| def url_is_authorization_code(self): | ||
| """ | ||
| Verifies that the authorization URL is the GitHub OAuth authorization URL. | ||
|
|
||
| Raises: | ||
| ValueError: If the URL does not match the expected pattern. | ||
| """ | ||
| if not re.match(GITHUB_AUTHORIZATION_URL, self.response["url"]): | ||
| raise ValueError("URL should match GitHub OAuth authorization URL pattern") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.