-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'opensearch-project:main' into main
- Loading branch information
Showing
66 changed files
with
14,192 additions
and
279 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
name: Keycloak Build and Test | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- keycloak/** | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: keycloak | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 16.x | ||
|
||
- name: Run CDK Build and Test | ||
run: | | ||
npm install | ||
npm run build | ||
- name: Run test coverage | ||
run: | | ||
npm test -- --coverage | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 |
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,23 @@ | ||
*.js | ||
!.eslintrc.js | ||
!jest.config.js | ||
*.d.ts | ||
node_modules | ||
cdk.context.json | ||
.DS_Store | ||
lib/.DS_Store | ||
|
||
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# coverage output | ||
coverage.lcov | ||
|
||
# excluding intellij Idea files | ||
*.iml | ||
.idea/ | ||
.vscode/ |
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,13 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
requests = "*" | ||
|
||
[dev-packages] | ||
|
||
[requires] | ||
python_version = "3.10" | ||
python_full_version = "3.10.13" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -6,3 +6,5 @@ node_modules | |
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out | ||
.DS_Store | ||
../.DS_Store |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
79 changes: 79 additions & 0 deletions
79
benchmark-control-plane/infra/lib/lambda/test/test_custom_lambda_authorizer.py
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,79 @@ | ||
import json | ||
import sys | ||
import os | ||
from unittest.mock import patch, MagicMock | ||
import pytest | ||
|
||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
from custom_lambda_auth import generate_policy, check_user_permission, lambda_handler | ||
|
||
|
||
@pytest.fixture | ||
def mock_requests(): | ||
with patch('custom_lambda_auth.requests') as mock: | ||
yield mock | ||
|
||
|
||
@pytest.fixture | ||
def mock_boto3(): | ||
with patch('custom_lambda_auth.boto3') as mock: | ||
yield mock | ||
|
||
|
||
def test_lambda_handler_valid_token(mock_requests): | ||
# Mock the GitHub API response | ||
mock_response = MagicMock() | ||
mock_response.status_code = 200 | ||
mock_response.json.return_value = {'login': 'testuser'} | ||
mock_requests.get.return_value = mock_response | ||
|
||
# Mock the check_user_permission function | ||
with patch('custom_lambda_auth.check_user_permission', return_value=True): | ||
event = { | ||
'authorizationToken': 'valid_token', | ||
'methodArn': 'arn:aws:execute-api:us-east-1:123456789012:api-id/stage/method/resource-path' | ||
} | ||
result = lambda_handler(event, {}) | ||
|
||
assert result['policyDocument']['Statement'][0]['Effect'] == 'Allow' | ||
assert result['principalId'] == 'testuser' | ||
|
||
|
||
def test_lambda_handler_invalid_token(mock_requests): | ||
# Mock the GitHub API response for invalid token | ||
mock_response = MagicMock() | ||
mock_response.status_code = 401 | ||
mock_response.json.return_value = {'login': 'testuser'} | ||
mock_requests.get.return_value = mock_response | ||
|
||
with patch('custom_lambda_auth.check_user_permission'): | ||
event = { | ||
'authorizationToken': 'invalid_token', | ||
'methodArn': 'arn:aws:execute-api:us-east-1:123456789012:api-id/stage/method/resource-path' | ||
} | ||
result = lambda_handler(event, {}) | ||
|
||
assert result['policyDocument']['Statement'][0]['Effect'] == 'Deny' | ||
assert result['principalId'] == 'testuser' | ||
|
||
|
||
def test_lambda_handler_no_token(): | ||
event = { | ||
'methodArn': 'arn:aws:execute-api:us-east-1:123456789012:api-id/stage/method/resource-path' | ||
} | ||
result = lambda_handler(event, {}) | ||
|
||
assert result['policyDocument']['Statement'][0]['Effect'] == 'Deny' | ||
assert result['principalId'] == 'user' | ||
|
||
|
||
def test_generate_policy(): | ||
method_arn = 'arn:aws:execute-api:us-east-1:123456789012:api-id/stage/method/resource-path' | ||
effect = 'Allow' | ||
principal_id = 'testuser' | ||
|
||
policy = generate_policy(method_arn, effect, principal_id) | ||
|
||
assert policy['principalId'] == principal_id | ||
assert policy['policyDocument']['Statement'][0]['Effect'] == effect | ||
assert policy['policyDocument']['Statement'][0]['Resource'] == method_arn |
Oops, something went wrong.