Skip to content

feat: apiml Spring-Modulith based module with ZAAS service #4108

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

Open
wants to merge 405 commits into
base: v3.x.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
405 commits
Select commit Hold shift + click to select a range
4cc5ad9
use gateway test fixtures - add eureka homepage test
Apr 11, 2025
5a7742d
add unit tests for coverage
Apr 11, 2025
6b18176
use spring cloud discovery client
Apr 11, 2025
0f5ae19
Merge remote-tracking branch 'origin/v3.x.x' into reboot/modulith
Apr 11, 2025
8c02f41
remove outdated TODO comment
Apr 11, 2025
61340ca
try ignore sonar in EurekaConfiguration class copied
Apr 11, 2025
c13c6a0
Merge branch 'v3.x.x' into reboot/modulith
pablocarle Apr 13, 2025
0e6988b
add static definition processing to apiml component
Apr 15, 2025
c39aef4
Merge branch 'v3.x.x' into reboot/modulith
pablocarle Apr 15, 2025
fa252e0
Merge branch 'v3.x.x' into reboot/modulith
pablocarle Apr 16, 2025
243cc16
Merge branch 'v3.x.x' into reboot/modulith
pablocarle Apr 16, 2025
dcd3745
suprerss warnings for generic type wildcard
Apr 16, 2025
cde2278
Merge branch 'reboot/modulith' of https://github.com/zowe/api-layer i…
Apr 16, 2025
78f5ade
fix sonar issues
Apr 16, 2025
c4b2d69
fix low sonar issues
Apr 16, 2025
3f34725
Merge branch 'v3.x.x' into reboot/modulith
pablocarle Apr 25, 2025
36016e3
zaas to modulith
Shobhajayanna Apr 25, 2025
0bd3957
zaas to modulith
pj892031 Feb 7, 2025
26d4bed
refactor of usage ZAAS from the routing
pj892031 Feb 7, 2025
5662c70
zaas to modulith
Shobhajayanna Feb 10, 2025
e957367
zaas to modulith test foxes
Shobhajayanna Apr 28, 2025
baaf370
Merge branch 'v3.x.x' into reboot/modulith
achmelo Apr 29, 2025
606d44e
Merge remote-tracking branch 'origin/reboot/modulith' into reboot/mod…
achmelo Apr 29, 2025
9923052
basic and x509 login
achmelo May 9, 2025
88b60f0
working logout
achmelo May 13, 2025
1211d5f
Merge remote-tracking branch 'origin/v3.x.x' into reboot/modulith-zaas
achmelo May 13, 2025
142860f
start of query
achmelo May 13, 2025
9c5249a
update comments
achmelo May 13, 2025
abb63a6
update imports
achmelo May 13, 2025
df4ce46
query JWT
achmelo May 13, 2025
70207a8
refresh
achmelo May 13, 2025
774c99f
working success refresh
achmelo May 14, 2025
8d2702d
ticket endpoint
achmelo May 14, 2025
e832194
remove forward
achmelo May 14, 2025
00ba8c3
JWKs
achmelo May 14, 2025
b84a34f
wip - add pat generation and revoke
taban03 May 14, 2025
deb2ab0
use application sslcontext instead of default to retrieve JWK
achmelo May 15, 2025
46c99f6
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo May 15, 2025
1df82f2
add revokation for multiple tokens
taban03 May 15, 2025
4626c6b
add revokation for token by user
taban03 May 15, 2025
1fe25ba
validate oidc token
achmelo May 15, 2025
fc1fea1
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo May 15, 2025
a82442a
add revokation for token by scope
taban03 May 15, 2025
fac461e
add pat validation controller
taban03 May 15, 2025
a1238a2
use the new BasicLoginFilter in the eureka security filter chain
taban03 May 15, 2025
21fa5c8
do not wait for zaas
achmelo May 15, 2025
326043a
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo May 16, 2025
1972054
security filters
achmelo May 16, 2025
1812bb9
x509 auth
achmelo May 16, 2025
c9176ac
wip - replace the old token auth provider with the local one
taban03 May 16, 2025
072d97e
user original gateway error handling
achmelo May 16, 2025
5e295d9
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo May 16, 2025
60180d5
wip - add error handling
taban03 May 16, 2025
8eb685f
auth failure handler for basic auth
achmelo May 16, 2025
88987f0
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo May 16, 2025
1a2a413
do not override buffer
achmelo May 16, 2025
6394f1a
revert negated matcher
achmelo May 16, 2025
5b5d9dc
improve error handling for pat generation
taban03 May 16, 2025
cc26d15
polishing
taban03 May 16, 2025
fbe7e57
Merge branch 'v3.x.x' into reboot/modulith-zaas
taban03 May 19, 2025
0563292
fix bug with ui
taban03 May 20, 2025
5350727
polishing + adding missing code
taban03 May 20, 2025
abc70fe
use the refactored handler in all the servlet filters and fix tests
taban03 May 21, 2025
4b67894
Merge branch 'v3.x.x' into reboot/modulith-zaas
taban03 May 21, 2025
231b74f
add javadoc
taban03 May 21, 2025
1bad7e3
make gw landpage work on both mode
taban03 May 21, 2025
3013b65
fix tests
taban03 May 22, 2025
14735c8
do not start zaas when modulith in ITs
taban03 May 22, 2025
b8976e7
add /auth/check controller and fix ITs
taban03 May 22, 2025
b41bb47
add handler for /check
taban03 May 22, 2025
bf9a533
refactor
taban03 May 22, 2025
5907966
remove zaas
taban03 May 22, 2025
09bfbbf
update docker config
taban03 May 22, 2025
f6289b5
fix config reader
taban03 May 23, 2025
b48d510
fix
taban03 May 23, 2025
d5488cc
wip - fix its
taban03 May 23, 2025
d2cf6c4
Merge branch 'v3.x.x' into reboot/modulith-zaas
taban03 May 26, 2025
a2aa3d8
fix checkstyle and license violation
May 26, 2025
ef7779a
fixes for OIDCTokenProviderJWKTest
May 27, 2025
9f7dcc3
Fix ZosmfServiceTest
May 27, 2025
42d0274
Fix AuthExcptionHandlerTest
May 27, 2025
7a12913
fix for LoginFilterTest
May 27, 2025
1224198
fix imports
May 27, 2025
0a52325
Fix for UnauthorizedHandlerTest
May 27, 2025
575dbf8
Fix for BearerContentFilterTest
May 27, 2025
97b12af
fix schemas
taban03 May 28, 2025
1958652
fix health endpoint
taban03 May 28, 2025
7f3bb14
fix remaining unit tests
May 28, 2025
bbc63f3
Merge branch 'reboot/modulith-zaas' of https://github.com/zowe/api-la…
May 28, 2025
3c7fb70
Merge branch 'v3.x.x' into reboot/modulith-zaas
pablocarle May 28, 2025
821f702
change to methodNotAllowed
taban03 May 29, 2025
77dcaa2
fix test and improve error handling for servlet and webflux based
taban03 May 29, 2025
c445658
fix build
taban03 May 29, 2025
e12de0a
fix protection of health endpoint
taban03 May 29, 2025
0f112bb
polishing
taban03 May 29, 2025
19512fd
add specific filter chain to protect /application/**
taban03 May 30, 2025
1e0427c
Fix LogoutHandler.java to properly extract the bearer token from the …
taban03 May 30, 2025
de14e96
use flux
May 30, 2025
74538df
Merge branch 'reboot/modulith-zaas' of https://github.com/zowe/api-la…
May 30, 2025
b235061
extract the x509 from the request attribute correctly
taban03 May 30, 2025
e5820d9
disable filter in gateway on modulith for services endpoint
May 30, 2025
3336c34
Merge branch 'v3.x.x' into reboot/modulith-zaas
pablocarle May 30, 2025
7c25753
add javadoc
taban03 May 30, 2025
d275a5a
return proper message in case of token expired
taban03 May 30, 2025
8e4d8c7
fixed return message in case of missing auth
taban03 May 30, 2025
ec600a3
fix passticket test
taban03 Jun 1, 2025
72e232b
add check for missing username or pw in basic auth for login
taban03 Jun 2, 2025
500ce0b
add registry and services endpoint security filters
Jun 2, 2025
b6d4c8a
Merge branch 'v3.x.x' into reboot/modulith-zaas
pablocarle Jun 2, 2025
017c3ac
fix issue with basic auth filter
taban03 Jun 2, 2025
5c89960
assert correctly
taban03 Jun 2, 2025
b8b3b2c
use controller for access-token generate
Jun 3, 2025
bb688ca
change the login filter to correctly return message in case of wrong …
taban03 Jun 3, 2025
d989dc4
remove unneeded handling
Jun 3, 2025
bb4e8b5
unify messages
taban03 Jun 3, 2025
4069948
fix /version test
taban03 Jun 3, 2025
788e57e
fix for passticket generation failure
Jun 3, 2025
71549f3
fix unit tests
taban03 Jun 3, 2025
e7a36c5
secure cookie, add StoreAccessTokenInfoWebFilter unit tests
Jun 4, 2025
deed5a3
add TokenAuthenticationFilterTest
Jun 4, 2025
63c8998
test reactive auth controller
achmelo Jun 4, 2025
acc13fb
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo Jun 4, 2025
7233556
fixes in controllers in case of empty authentication
Jun 4, 2025
8ef7dc0
fix issue with checkign body credentials for non /login requests
taban03 Jun 4, 2025
8747564
fix check
taban03 Jun 4, 2025
74db346
fix for x509authfilter
Jun 4, 2025
f0fe978
add tests for ReactiveSafResourceAccessController.java
taban03 Jun 4, 2025
bab24bd
add unit tests for user-actions.jsx
taban03 Jun 4, 2025
5fc49c9
create test for app.jsx
taban03 Jun 4, 2025
ffb55bc
add test
taban03 Jun 4, 2025
0a9bcf8
add test for auth controller
taban03 Jun 4, 2025
c474948
add tests for ErrorHeaders.java and HttpUtils.java
taban03 Jun 4, 2025
15cce36
add tests for ZaasSchemeTransformApiTest.java
taban03 Jun 4, 2025
cf6155f
add tests for LocalTokenProvider, SuccessQueryHandler and SuccessRefr…
taban03 Jun 4, 2025
de8d8b6
add x509AuthFilterTest
Jun 5, 2025
4516d94
add test for failed authentication web handler
taban03 Jun 5, 2025
0a7a587
add tests for ZaasSchemeTransformApiTest
taban03 Jun 5, 2025
2ac4298
add test for SuccessTicketHandler.java
taban03 Jun 5, 2025
acfb965
add tests for LogoutHandler.java
taban03 Jun 5, 2025
941d610
Add integration tests for Saf auth check endpoint
taban03 Jun 5, 2025
afce242
avoid NPE
taban03 Jun 5, 2025
dcb16cd
increase coverage for ZaasSchemeTransformApiTest
taban03 Jun 5, 2025
c3361c1
QueryWebFilterTest
Jun 5, 2025
48d5795
refactor basic auth login, add unit tests
achmelo Jun 5, 2025
43345be
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo Jun 5, 2025
ef6608a
add tag
taban03 Jun 5, 2025
48b30e5
fix checkstyle
taban03 Jun 5, 2025
4a83c36
add back the login path check
taban03 Jun 5, 2025
68b7ebe
fix tests
taban03 Jun 5, 2025
4d137dd
Merge branch 'v3.x.x' into reboot/modulith-zaas
pablocarle Jun 6, 2025
f3fa287
address sonar issues and add tests
taban03 Jun 6, 2025
7f0939f
rename fields
achmelo Jun 6, 2025
e0a0a48
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo Jun 6, 2025
b7b7ed3
fix issues
taban03 Jun 6, 2025
2aeec1f
fix issues pt.3
taban03 Jun 6, 2025
97d26a3
test categorize certs filter
achmelo Jun 6, 2025
ec0871e
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo Jun 6, 2025
0222ed6
refactoring to reduce the complexity and fix issues
taban03 Jun 6, 2025
ce4dfb3
cleanup and refactor
achmelo Jun 6, 2025
c83e948
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo Jun 6, 2025
35a8efd
correct attr name
achmelo Jun 6, 2025
474a018
remove duplicated code
achmelo Jun 6, 2025
2079094
simplify
achmelo Jun 6, 2025
70da998
align passticket scheme with the rest
achmelo Jun 9, 2025
e24eea0
address PR review comments - pt.1
taban03 Jun 9, 2025
1c6e6bd
update unit tests
achmelo Jun 9, 2025
254e6da
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo Jun 9, 2025
2f171e1
minor touches
Jun 9, 2025
0b2ec19
Merge branch 'reboot/modulith-zaas' of https://github.com/zowe/api-la…
Jun 9, 2025
e832318
address PR review comments
taban03 Jun 10, 2025
5b9723f
fix handling on passticket failure
taban03 Jun 10, 2025
71160bd
run zosmf jwt initialization
achmelo Jun 10, 2025
ace1d9e
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo Jun 10, 2025
ec43470
fix checkstyle
taban03 Jun 11, 2025
58be7eb
Merge branch 'v3.x.x' into reboot/modulith-zaas
taban03 Jun 11, 2025
009b983
Merge branch 'v3.x.x' into reboot/modulith-zaas
taban03 Jun 11, 2025
bc3936a
address pr comments
taban03 Jun 12, 2025
918e6ed
address pr comments pt.2
taban03 Jun 12, 2025
410ac68
address pr comments pt.3
taban03 Jun 12, 2025
7de740d
address pr comments pt.4
taban03 Jun 12, 2025
385a9f1
address pr comments pt.5
taban03 Jun 12, 2025
8fe1bf4
add additional check
taban03 Jun 12, 2025
3b8abca
fix test
taban03 Jun 12, 2025
99532c3
address comments pt.6
taban03 Jun 12, 2025
417891c
yse DataBufferUtils
taban03 Jun 12, 2025
4ea007d
revert back
taban03 Jun 12, 2025
01a35af
throw exception in case of error for LocalTokenProvider
taban03 Jun 12, 2025
ca07c8d
revert back
taban03 Jun 13, 2025
733f7fc
revert back
taban03 Jun 13, 2025
924c612
fix gitignore
Jun 13, 2025
c36946d
Merge branch 'reboot/modulith-zaas' of https://github.com/zowe/api-la…
Jun 13, 2025
3841998
Merge branch 'v3.x.x' into reboot/modulith-zaas
pablocarle Jun 13, 2025
6c19718
refactoring of CategorizeCertsWebFilter to use optional
taban03 Jun 13, 2025
071148b
address comments
taban03 Jun 13, 2025
33efbc0
address comments
taban03 Jun 13, 2025
ffb2a3f
Merge branch 'reboot/modulith-zaas' of https://github.com/zowe/api-la…
Jun 13, 2025
1e3f144
address comments
taban03 Jun 13, 2025
c784f28
PR review - refactoring test
taban03 Jun 13, 2025
2bc3a9a
Merge branch 'v3.x.x' into reboot/modulith-zaas
pablocarle Jun 13, 2025
6f464a5
address review
taban03 Jun 16, 2025
4f0638a
address review
taban03 Jun 16, 2025
61980ea
Merge branch 'v3.x.x' into reboot/modulith-zaas
taban03 Jun 16, 2025
0b5b11a
remove redundant check
taban03 Jun 16, 2025
c023b14
use webflux syntax
taban03 Jun 16, 2025
cc3c70b
address some of the sonarqube issues
Jun 16, 2025
374504a
use exception handler
taban03 Jun 17, 2025
c22b573
fix tests
taban03 Jun 17, 2025
4ce419f
wip pr review
Jun 17, 2025
f682b58
refactor passticket ex handling
taban03 Jun 17, 2025
46cea13
fix
taban03 Jun 17, 2025
3975069
change applicationInfo to builder
taban03 Jun 17, 2025
0ee61df
fix checkstyle
taban03 Jun 17, 2025
2c1de32
refactor tests
taban03 Jun 18, 2025
4025ce2
refactoring of HttpUtils
taban03 Jun 18, 2025
77d49b7
trigger JWT listener init upon eureka registry event
taban03 Jun 18, 2025
53123b3
rename GWs AcceptanceTest to MicroservicesAcceptanceTest
Jun 18, 2025
982525b
pr review, refactor filters, split controllers add controller endpoints
Jun 18, 2025
8499e6f
Merge branch 'v3.x.x' into reboot/modulith-zaas
pablocarle Jun 18, 2025
8be47d5
roll back zosmf init change
taban03 Jun 18, 2025
c3309ae
wip fix login filter security config
Jun 18, 2025
d142d14
refactor handler and add back z/osmf init listener
taban03 Jun 18, 2025
5697872
fix PassTicketTest ITs
Jun 19, 2025
c6bca98
use exception handler, try fix negative case to follow non-modulith
Jun 19, 2025
d7aa9f1
fix unit test
Jun 19, 2025
79bea4d
Merge branch 'v3.x.x' into reboot/modulith-zaas
pablocarle Jun 19, 2025
347e7e3
pr review
Jun 19, 2025
04afb45
pr review (pat rauditx comment)
Jun 19, 2025
9065837
Merge branch 'v3.x.x' into reboot/modulith-zaas
pablocarle Jun 19, 2025
77ba9a1
rename AuthServiceIdChooserConfig.java and remove conditional missing…
taban03 Jun 18, 2025
1190050
address comments
taban03 Jun 19, 2025
104729d
maintain support for "incorrect" login post requests
Jun 19, 2025
fa52b60
Merge branch 'reboot/modulith-zaas' of https://github.com/zowe/api-la…
Jun 19, 2025
ea773e0
add missing code
taban03 Jun 19, 2025
5e45e20
pr review
Jun 19, 2025
0eeda0d
separate exception, use message instead of key
achmelo Jun 19, 2025
8d8e6f4
Merge remote-tracking branch 'origin/reboot/modulith-zaas' into reboo…
achmelo Jun 19, 2025
4a76308
fix principal
Jun 19, 2025
1997be7
pr review
Jun 19, 2025
96745a3
pr review (remove extra onErrorResume)
Jun 19, 2025
4422990
wip comment and order security filter chains
Jun 20, 2025
5ba6a0f
try fix flaky UI E2E test
Jun 20, 2025
4fb850c
add default 401 in passticket controller
Jun 20, 2025
c98baa7
fix missing openapi specs in gateway
Jun 20, 2025
e9145d2
manifest.yaml
Jun 20, 2025
1d23d58
review
Jun 20, 2025
992e2a4
fix openapi descriptions
Jun 20, 2025
9287836
revert change
Jun 20, 2025
58fdac6
fix non-existing message key, replace apiml log with debug message
Jun 20, 2025
df1d7fa
rev
Jun 20, 2025
b529798
address sonar issues
Jun 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
APIML_SECURITY_AUTH_JWT_CUSTOMAUTHHEADER: customJwtHeader
APIML_SECURITY_AUTH_PASSTICKET_CUSTOMUSERHEADER: customUserHeader
APIML_SECURITY_AUTH_PASSTICKET_CUSTOMAUTHHEADER: customPassticketHeader
APIML_SECURITY_X509_ENABLED: true
APIML_SECURITY_X509_CERTIFICATESURL: https://apiml:10010/gateway/certificates
SERVER_MAX_HTTP_REQUEST_HEADER_SIZE: 16348
SERVER_WEBSOCKET_REQUESTBUFFERSIZE: 16348
APIML_GATEWAY_SERVICESTOLIMITREQUESTRATE: discoverableclient
Expand All @@ -65,13 +67,6 @@ jobs:
image: ghcr.io/balhar-jakub/discoverable-client:${{ github.run_id }}-${{ github.run_number }}
env:
APIML_SERVICE_DISCOVERYSERVICEURLS: https://apiml:10011/eureka
zaas-service:
image: ghcr.io/balhar-jakub/zaas-service:${{ github.run_id }}-${{ github.run_number }}
env:
APIML_SECURITY_X509_ENABLED: true
APIML_SECURITY_X509_ACCEPTFORWARDEDCERT: true
APIML_SECURITY_X509_CERTIFICATESURL: https://apiml:10010/gateway/certificates
APIML_SERVICE_DISCOVERYSERVICEURLS: https://apiml:10011/eureka
mock-services:
image: ghcr.io/balhar-jakub/mock-services:${{ github.run_id }}-${{ github.run_number }}
env:
Expand All @@ -86,7 +81,7 @@ jobs:
- name: Run CI Tests
run: >
ENV_CONFIG=docker-modulith ./gradlew runStartUpCheck :integration-tests:runContainerModulithTests --info
-Ddiscoverableclient.instances=1 -Denvironment.config=-docker-modulith
-Ddiscoverableclient.instances=1 -Denvironment.config=-docker-modulith -Denvironment.modulith=true
-Partifactory_user=${{ secrets.ARTIFACTORY_USERNAME }} -Partifactory_password=${{ secrets.ARTIFACTORY_PASSWORD }}
- uses: ./.github/actions/dump-jacoco
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bin
!api-catalog-package/src/main/resources/bin
!discovery-package/src/main/resources/bin
!caching-service-package/src/main/resources/bin
!zaas-service-package/src/main/resources/bin
!zaas-package/src/main/resources/bin
!apiml-package/src/main/resources/bin
var
sdist
Expand Down
10 changes: 10 additions & 0 deletions api-catalog-ui/frontend/src/actions/user-actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ function login(credentials) {
};
}

export function forceLogout() {
return (dispatch) => {
dispatch({ type: userConstants.USERS_LOGOUT_SUCCESS });
};
}

export function query(user) {
const success = { showUpdatePassSuccess: true };
return { type: userConstants.USERS_LOGIN_SUCCESS, user, success };
Expand All @@ -77,6 +83,9 @@ function logout() {
userService.logout().then(
() => {
dispatch(success());
const channel = new BroadcastChannel('auth_channel');
channel.postMessage('logout');
channel.close();
},
(error) => {
dispatch(failure(error));
Expand Down Expand Up @@ -123,4 +132,5 @@ export const userActions = {
validateInput,
closeAlert,
query,
forceLogout,
};
46 changes: 46 additions & 0 deletions api-catalog-ui/frontend/src/actions/user-actions.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import { userService } from '../services';

describe('>>> User actions tests', () => {
const credentials = { username: 'user', password: 'password' };
const mockPostMessage = jest.fn();
const mockClose = jest.fn();

global.BroadcastChannel = class {
constructor() {
this.postMessage = mockPostMessage;
this.close = mockClose;
}
};

it('should close alert', () => {
const expectedAction = {
Expand Down Expand Up @@ -89,4 +98,41 @@ describe('>>> User actions tests', () => {
expect(action.type).toBe('USERS_LOGIN_SUCCESS');
expect(action.user).toBe('user');
});

it('should dispatch USERS_LOGOUT_SUCCESS in forceLogout', () => {
const dispatch = jest.fn();

userActions.forceLogout()(dispatch);

expect(dispatch).toHaveBeenCalledWith({
type: userConstants.USERS_LOGOUT_SUCCESS
});
});

it('should dispatch logout success and broadcast logout on success', async () => {
const dispatch = jest.fn();

userService.logout = jest.fn().mockResolvedValue();

await userActions.logout()(dispatch);

expect(dispatch).toHaveBeenCalledWith({ type: userConstants.USERS_LOGOUT_REQUEST });
expect(dispatch).toHaveBeenCalledWith({ type: userConstants.USERS_LOGOUT_SUCCESS });

const channelCall = new BroadcastChannel('auth_channel');
expect(channelCall.postMessage).toHaveBeenCalledWith('logout');
expect(channelCall.close).toHaveBeenCalled();
});

it('should dispatch logout failure on error', async () => {
const dispatch = jest.fn();
const error = new Error('Logout failed');

userService.logout = jest.fn().mockRejectedValue(error);

await userActions.logout()(dispatch);

expect(dispatch).toHaveBeenCalledWith({ type: userConstants.USERS_LOGOUT_REQUEST });
expect(dispatch).toHaveBeenCalledWith({ type: userConstants.USERS_LOGOUT_FAILURE, error });
});
});
19 changes: 18 additions & 1 deletion api-catalog-ui/frontend/src/components/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function App(props) {
useEffect(() => {
window.process = { ...window.process };
}, []);
const { authentication, success } = props;
const { authentication, success, logout } = props;
useEffect(() => {
const checkAuth = () => {
if (!authentication.user) {
Expand All @@ -48,8 +48,25 @@ function App(props) {
// Run again whenever the tab gains focus
window.addEventListener('focus', checkAuth);

const authChannel = new BroadcastChannel('auth_channel');
authChannel.onmessage = (event) => {
if (event.data === 'logout') {
logout();
navigate('/login');
}

if (event.data === 'login') {
userService.query().then((result) => {
if (result.status === 200) {
success(result.userId, false);
}
});
}
};

return () => { // Remove immediately to avoid loop
window.removeEventListener('focus', checkAuth);
authChannel.close();
};
}, [authentication.user, success, navigate]);

Expand Down
81 changes: 81 additions & 0 deletions api-catalog-ui/frontend/src/components/App/App.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { userService } from "../../services";

const mockNavigate = jest.fn();
const mockLocation = jest.fn();
let broadcastInstance;

jest.mock('react-router', () => {
return {
__esModule: true,
Expand Down Expand Up @@ -45,6 +47,22 @@ async function assertMethod(mockSuccess) {
}

describe('>>> App component tests', () => {

beforeAll(() => {
global.BroadcastChannel = class {
constructor() {
this.onmessage = null;
broadcastInstance = this;
}
postMessage(msg) {
if (this.onmessage) {
this.onmessage({ data: msg });
}
}
close() {}
};
});

it('should call render', () => {
const history = { push: jest.fn() };
const success = { push: jest.fn() };
Expand Down Expand Up @@ -108,4 +126,67 @@ describe('>>> App component tests', () => {
userService.query.mockRejectedValue(new Error('Network error'));
await assertMethod(mockSuccess);
});

it('handles BroadcastChannel logout message', async () => {
const mockLogout = jest.fn();
const mockSuccess = jest.fn();

await act(async () => {
render(
<MemoryRouter initialEntries={['/dashboard']}>
<App authentication={{ user: 'user' }} success={mockSuccess} logout={mockLogout} />
</MemoryRouter>
);
});

broadcastInstance.onmessage({ data: 'logout' });

expect(mockLogout).toHaveBeenCalled();
expect(mockNavigate).toHaveBeenCalledWith('/login');
});

it('handles BroadcastChannel login message and calls success if 200', async () => {
const mockLogout = jest.fn();
const mockSuccess = jest.fn();
userService.query.mockResolvedValue({ status: 200, userId: 'mockedUser' });

await act(async () => {
render(
<MemoryRouter initialEntries={['/dashboard']}>
<App authentication={{ user: 'user' }} success={mockSuccess} logout={mockLogout} />
</MemoryRouter>
);
});

broadcastInstance.onmessage({ data: 'login' });

await waitFor(() => {
expect(userService.query).toHaveBeenCalled();
expect(mockSuccess).toHaveBeenCalledWith('mockedUser', false);
});
});

it('handles BroadcastChannel login message but does NOT call success if status !== 200', async () => {
const mockLogout = jest.fn();
const mockSuccess = jest.fn();
userService.query.mockResolvedValue({ status: 403 });

await act(async () => {
render(
<MemoryRouter initialEntries={['/dashboard']}>
<App authentication={{ user: 'user' }} success={mockSuccess} logout={mockLogout} />
</MemoryRouter>
);
});

await act(async () => {
broadcastInstance.onmessage({ data: 'login' });
});

await waitFor(() => {
expect(userService.query).toHaveBeenCalled();
expect(mockSuccess).not.toHaveBeenCalled();
});
});

});
10 changes: 2 additions & 8 deletions api-catalog-ui/frontend/src/components/App/AppContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,14 @@ import App from './App';
import { connect } from "react-redux";
import { userActions } from '../../actions/user-actions';

const withRouter = (App) =>{
return (props) =>{
return <App {...props}/>
}
}

const mapDispatchToProps = (dispatch) => ({
success: (user) => dispatch(userActions.query(user)),
logout: () => dispatch(userActions.forceLogout()),
});


const mapStateToProps = (state) => ({
authentication: state.authenticationReducer,
});


export default connect(mapStateToProps, mapDispatchToProps)(withRouter(App))
export default connect(mapStateToProps, mapDispatchToProps)(App);
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ describe('App Container', () => {
);
});

beforeAll(() => {
global.BroadcastChannel = class {
close() {}
};
});

it('should render the container', () => {
expect(container).not.toBeNull();
});
Expand Down
11 changes: 7 additions & 4 deletions api-catalog-ui/frontend/src/components/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@ function Dashboard({
}) {
const navigate = useNavigate();
useEffect(() => {
clearService();
fetchTilesStart();
if (!authentication.user) {
navigate('/login');
return;
}
clearService();
fetchTilesStart();
return function cleanup () {
clear();
}
}, []);
}, [authentication.user, navigate]);

if (!authentication.user) {
return null;
}
const hasSearchCriteria =
typeof searchCriteria !== 'undefined' &&
searchCriteria !== undefined &&
Expand All @@ -76,7 +80,6 @@ function Dashboard({
if (hasTiles) {
allServices = sortServices(tiles);
}

return (
<div className="main-content dashboard-content">
<div id="dash-buttons">
Expand Down
Loading
Loading