generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: network error upon login for tsc admin profile (#1381)
Co-authored-by: Derek Roberts <derek.roberts@gmail.com>
- Loading branch information
1 parent
1248fad
commit f396b42
Showing
9 changed files
with
199 additions
and
56 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
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
103 changes: 103 additions & 0 deletions
103
backend/src/test/java/ca/bc/gov/backendstartapi/security/LoggedUserServiceTest.java
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,103 @@ | ||
package ca.bc.gov.backendstartapi.security; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
import ca.bc.gov.backendstartapi.exception.ClientIdForbiddenException; | ||
import ca.bc.gov.backendstartapi.exception.UserNotFoundException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
class LoggedUserServiceTest { | ||
|
||
@Mock UserAuthenticationHelper userAuthenticationHelper; | ||
|
||
private LoggedUserService loggedUserService; | ||
|
||
@BeforeEach | ||
void setup() { | ||
loggedUserService = new LoggedUserService(userAuthenticationHelper); | ||
} | ||
|
||
private UserInfo mockUserInfo(Set<String> roles, List<String> clients) { | ||
return new UserInfo( | ||
"123456789@idir", | ||
"Bilbo", | ||
"Baggings", | ||
"bilbo.baggings@gov.bc.ca", | ||
"Baggings, Bilbo LWRS:EX", | ||
"BAGGINGS", | ||
null, | ||
IdentityProvider.IDIR, | ||
roles != null ? roles : Set.of(), | ||
clients != null ? clients : List.of(), | ||
"abcdef123456789"); | ||
} | ||
|
||
@Test | ||
@DisplayName("Verify seedlot access privilege happy path should succeed") | ||
void verifySeedlotAccessPrivilege_happyPath_shouldSucceed() { | ||
String clientId = "00012345"; | ||
|
||
when(userAuthenticationHelper.getUserInfo()) | ||
.thenReturn( | ||
Optional.of(mockUserInfo(Set.of("FAKE_ROLE_TEST_00012345"), List.of("00012345")))); | ||
|
||
Assertions.assertDoesNotThrow( | ||
() -> { | ||
loggedUserService.verifySeedlotAccessPrivilege(clientId); | ||
}); | ||
} | ||
|
||
@Test | ||
@DisplayName("Verify seedlot access privilege no user should succeed") | ||
void verifySeedlotAccessPrivilege_noUser_shouldSucceed() { | ||
String clientId = "00012345"; | ||
|
||
when(userAuthenticationHelper.getUserInfo()).thenReturn(Optional.empty()); | ||
|
||
Assertions.assertThrows( | ||
UserNotFoundException.class, | ||
() -> { | ||
loggedUserService.verifySeedlotAccessPrivilege(clientId); | ||
}); | ||
} | ||
|
||
@Test | ||
@DisplayName("Verify seedlot access privilege tsc admin should succeed") | ||
void verifySeedlotAccessPrivilege_tscAdmin_shouldSucceed() { | ||
String clientId = "00012345"; | ||
|
||
when(userAuthenticationHelper.getUserInfo()) | ||
.thenReturn(Optional.of(mockUserInfo(Set.of("SPAR_TSC_ADMIN"), null))); | ||
|
||
Assertions.assertDoesNotThrow( | ||
() -> { | ||
loggedUserService.verifySeedlotAccessPrivilege(clientId); | ||
}); | ||
} | ||
|
||
@Test | ||
@DisplayName("Verify seedlot access privilege regular user should fail") | ||
void verifySeedlotAccessPrivilege_regularUser_shouldSucceed() { | ||
String clientId = "00012345"; | ||
|
||
when(userAuthenticationHelper.getUserInfo()) | ||
.thenReturn( | ||
Optional.of(mockUserInfo(Set.of("FAKE_ROLE_TEST_00012345"), List.of("00012346")))); | ||
|
||
Assertions.assertThrows( | ||
ClientIdForbiddenException.class, | ||
() -> { | ||
loggedUserService.verifySeedlotAccessPrivilege(clientId); | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,30 +1,46 @@ | ||
import React from 'react'; | ||
|
||
import React, { useContext } from 'react'; | ||
import { Row, Column } from '@carbon/react'; | ||
|
||
import StandardCard from '../Card/StandardCard'; | ||
import { cards } from './constants'; | ||
|
||
import './styles.scss'; | ||
import AuthContext from '../../contexts/AuthContext'; | ||
|
||
const SeedlotCards = () => { | ||
const { isTscAdmin } = useContext(AuthContext); | ||
|
||
const SeedlotCards = () => ( | ||
<Row className="seedlot-activities-cards"> | ||
{ | ||
cards.map((card) => ( | ||
<Column sm={4} md={4} lg={8} xlg={8} max={4} key={card.id}> | ||
<StandardCard | ||
image={card.image} | ||
header={card.header} | ||
description={card.description} | ||
url={card.link} | ||
isEmpty={card.isEmpty} | ||
emptyTitle={card.emptyTitle} | ||
emptyDescription={card.emptyDescription} | ||
/> | ||
</Column> | ||
)) | ||
const shouldDisplayCard = (card: any) => { | ||
let display = card.displayForNonAdmin; | ||
if (isTscAdmin && display === true) { | ||
display = true; | ||
} | ||
</Row> | ||
); | ||
if (!isTscAdmin) { | ||
return card.displayForNonAdmin; | ||
} | ||
if (!card.displayForAdmin) { | ||
return false; | ||
} | ||
return card.displayForAdmin; | ||
}; | ||
|
||
return ( | ||
<Row className="seedlot-activities-cards"> | ||
{ | ||
cards.filter((c) => shouldDisplayCard(c)).map((card) => ( | ||
<Column sm={4} md={4} lg={8} xlg={8} max={4} key={card.id}> | ||
<StandardCard | ||
image={card.image} | ||
header={card.header} | ||
description={card.description} | ||
url={card.link} | ||
isEmpty={card.isEmpty} | ||
emptyTitle={card.emptyTitle} | ||
emptyDescription={card.emptyDescription} | ||
/> | ||
</Column> | ||
)) | ||
} | ||
</Row> | ||
); | ||
}; | ||
|
||
export default SeedlotCards; |
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