clean up
This commit is contained in:
+8
-8
@@ -31,9 +31,9 @@ class ApplicationPropertiesSaml2HttpTest {
|
||||
String url = server.url("/meta").toString();
|
||||
|
||||
var s = new ApplicationProperties.Security.SAML2();
|
||||
s.setIdpMetadataUri(url);
|
||||
s.setMetadataUri(url);
|
||||
|
||||
try (InputStream in = s.getIdpMetadataUri()) {
|
||||
try (InputStream in = s.getMetadataUriAsStream()) {
|
||||
String body = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
assertTrue(body.contains("EntityDescriptor"));
|
||||
}
|
||||
@@ -44,9 +44,9 @@ class ApplicationPropertiesSaml2HttpTest {
|
||||
void idpMetadataUri_invalidUri_triggers_catch_and_throwsIOException() {
|
||||
// Ungültige URI -> new URI(...) wirft URISyntaxException -> catch -> IOException
|
||||
var s = new ApplicationProperties.Security.SAML2();
|
||||
s.setIdpMetadataUri("http:##invalid uri"); // absichtlich kaputt (Leerzeichen + ##)
|
||||
s.setMetadataUri("http:##invalid uri"); // absichtlich kaputt (Leerzeichen + ##)
|
||||
|
||||
assertThrows(IOException.class, s::getIdpMetadataUri);
|
||||
assertThrows(IOException.class, s::getMetadataUriAsStream);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,8 +57,8 @@ class ApplicationPropertiesSaml2HttpTest {
|
||||
Path tmp = Files.createTempFile("spdf-spcert-", ".crt");
|
||||
Files.writeString(tmp, "CERT");
|
||||
|
||||
s.setSpCert(tmp.toString());
|
||||
Resource r = s.getSpCert();
|
||||
s.getSp().setCert(tmp.toString());
|
||||
Resource r = s.getSp().getCertResource();
|
||||
|
||||
assertNotNull(r);
|
||||
assertInstanceOf(FileSystemResource.class, r, "Expected FileSystemResource for FS path");
|
||||
@@ -71,8 +71,8 @@ class ApplicationPropertiesSaml2HttpTest {
|
||||
|
||||
// bewusst nicht existierender Pfad -> else-Zweig wird trotzdem genommen
|
||||
String missing = "/this/path/does/not/exist/idp.crt";
|
||||
s.setIdpCert(missing);
|
||||
Resource r = s.getIdpCert();
|
||||
s.getProvider().setCert(missing);
|
||||
Resource r = s.getProvider().getCertResource();
|
||||
|
||||
assertNotNull(r);
|
||||
assertInstanceOf(FileSystemResource.class, r, "Expected FileSystemResource for FS path");
|
||||
|
||||
+15
-16
@@ -15,9 +15,9 @@ class ApplicationPropertiesSaml2ResourceTest {
|
||||
@Test
|
||||
void idpMetadataUri_classpath_is_resolved() throws Exception {
|
||||
var s = new ApplicationProperties.Security.SAML2();
|
||||
s.setIdpMetadataUri("classpath:saml/dummy.txt");
|
||||
s.setMetadataUri("classpath:saml/dummy.txt");
|
||||
|
||||
try (InputStream in = s.getIdpMetadataUri()) {
|
||||
try (InputStream in = s.getMetadataUriAsStream()) {
|
||||
assertNotNull(in, "Classpath InputStream should not be null");
|
||||
String txt = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
assertTrue(txt.contains("ok"));
|
||||
@@ -28,27 +28,26 @@ class ApplicationPropertiesSaml2ResourceTest {
|
||||
void spCert_idpCert_privateKey_null_classpath_and_filesystem() throws Exception {
|
||||
var s = new ApplicationProperties.Security.SAML2();
|
||||
|
||||
s.setSpCert(null);
|
||||
s.setIdpCert(null);
|
||||
s.setPrivateKey(null);
|
||||
assertNull(s.getSpCert());
|
||||
assertNull(s.getIdpCert());
|
||||
assertNull(s.getPrivateKey());
|
||||
// Test null values via the nested structure
|
||||
assertNull(s.getSp().getCertResource());
|
||||
assertNull(s.getProvider().getCertResource());
|
||||
assertNull(s.getSp().getPrivateKeyResource());
|
||||
|
||||
s.setSpCert("classpath:saml/dummy.txt");
|
||||
s.setIdpCert("classpath:saml/dummy.txt");
|
||||
s.setPrivateKey("classpath:saml/dummy.txt");
|
||||
Resource sp = s.getSpCert();
|
||||
Resource idp = s.getIdpCert();
|
||||
Resource pk = s.getPrivateKey();
|
||||
// Set classpath resources via the nested structure
|
||||
s.getSp().setCert("classpath:saml/dummy.txt");
|
||||
s.getProvider().setCert("classpath:saml/dummy.txt");
|
||||
s.getSp().setPrivateKey("classpath:saml/dummy.txt");
|
||||
Resource sp = s.getSp().getCertResource();
|
||||
Resource idp = s.getProvider().getCertResource();
|
||||
Resource pk = s.getSp().getPrivateKeyResource();
|
||||
assertTrue(sp.exists());
|
||||
assertTrue(idp.exists());
|
||||
assertTrue(pk.exists());
|
||||
|
||||
Path tmp = Files.createTempFile("spdf-key-", ".pem");
|
||||
Files.writeString(tmp, "KEY");
|
||||
s.setPrivateKey(tmp.toString());
|
||||
Resource pkFs = s.getPrivateKey();
|
||||
s.getSp().setPrivateKey(tmp.toString());
|
||||
Resource pkFs = s.getSp().getPrivateKeyResource();
|
||||
assertNotNull(pkFs);
|
||||
assertTrue(pkFs.exists());
|
||||
}
|
||||
|
||||
+6
@@ -27,6 +27,8 @@ class CustomLogoutSuccessHandlerTest {
|
||||
|
||||
@Mock private JwtServiceInterface jwtService;
|
||||
|
||||
@Mock private ApplicationProperties.Security.SAML2 saml2;
|
||||
|
||||
private CustomLogoutSuccessHandler customLogoutSuccessHandler;
|
||||
|
||||
@BeforeEach
|
||||
@@ -41,6 +43,8 @@ class CustomLogoutSuccessHandlerTest {
|
||||
String logoutPath = "/login?logout=true";
|
||||
|
||||
when(response.isCommitted()).thenReturn(false);
|
||||
when(securityProperties.getSaml2()).thenReturn(saml2);
|
||||
when(saml2.getEnableSingleLogout()).thenReturn(false);
|
||||
when(request.getContextPath()).thenReturn("");
|
||||
when(response.encodeRedirectURL(logoutPath)).thenReturn(logoutPath);
|
||||
|
||||
@@ -56,6 +60,8 @@ class CustomLogoutSuccessHandlerTest {
|
||||
String logoutPath = "/login?logout=true";
|
||||
|
||||
when(response.isCommitted()).thenReturn(false);
|
||||
when(securityProperties.getSaml2()).thenReturn(saml2);
|
||||
when(saml2.getEnableSingleLogout()).thenReturn(false);
|
||||
when(request.getContextPath()).thenReturn("");
|
||||
when(response.encodeRedirectURL(logoutPath)).thenReturn(logoutPath);
|
||||
|
||||
|
||||
@@ -252,7 +252,8 @@ describe('SpringAuthClient', () => {
|
||||
|
||||
describe('signOut', () => {
|
||||
let mockForm: { method: string; action: string; style: { display: string }; submit: ReturnType<typeof vi.fn> };
|
||||
let appendChildSpy: ReturnType<typeof vi.spyOn>;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let appendChildSpy: any;
|
||||
|
||||
beforeEach(() => {
|
||||
// Mock form creation and submission
|
||||
@@ -263,7 +264,7 @@ describe('SpringAuthClient', () => {
|
||||
submit: vi.fn(),
|
||||
};
|
||||
vi.spyOn(document, 'createElement').mockReturnValue(mockForm as unknown as HTMLElement);
|
||||
appendChildSpy = vi.spyOn(document.body, 'appendChild').mockImplementation(() => mockForm as unknown as HTMLFormElement);
|
||||
appendChildSpy = vi.spyOn(document.body, 'appendChild').mockImplementation((node) => node);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
|
||||
import { render, waitFor, cleanup } from '@testing-library/react';
|
||||
import { render, cleanup } from '@testing-library/react';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
import AuthCallback from '@app/routes/AuthCallback';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user