generated from it-at-m/oss-repository-en-template
-
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.
Tests vervollständigt, Schönheitsanpassungen
- Loading branch information
Showing
12 changed files
with
272 additions
and
121 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
61 changes: 61 additions & 0 deletions
61
...ty/src/test/java/de/muenchen/wls/common/security/BezirkIDPermissionEvaluatorImplTest.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,61 @@ | ||
package de.muenchen.wls.common.security; | ||
|
||
import de.muenchen.wls.common.security.testultils.LoggerExtension; | ||
import lombok.val; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContext; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
import java.util.HashMap; | ||
|
||
class BezirkIDPermissionEvaluatorImplTest { | ||
|
||
private final BezirkIDPermissionEvaluatorImpl unitUnderTest= new BezirkIDPermissionEvaluatorImpl(); | ||
|
||
@Nested | ||
class TestTokenUserBezirkIdMatches { | ||
|
||
|
||
@RegisterExtension | ||
public LoggerExtension loggerExtension = new LoggerExtension(); | ||
|
||
@Test | ||
void warnOnAuthenticationIsNull() { | ||
unitUnderTest.tokenUserBezirkIdMatches("1234",null); | ||
Assertions.assertThat(loggerExtension.getFormattedMessages().contains("No authentication object for bezirkId=1234")).isTrue(); | ||
} | ||
|
||
@Test | ||
void errorWhileChecking() { | ||
AuthenticationManager authManager = authentication -> authentication; | ||
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken("username", "password"); | ||
Authentication auth = authManager.authenticate(authRequest); | ||
SecurityContext context = SecurityContextHolder.createEmptyContext(); | ||
context.setAuthentication(auth); | ||
SecurityContextHolder.setContext(context); | ||
unitUnderTest.tokenUserBezirkIdMatches("1234", auth); | ||
Assertions.assertThat(loggerExtension.getFormattedMessages().contains("Error while checking bezirkId.")).isTrue(); | ||
} | ||
|
||
@Test | ||
void bezirkIDMatches() { | ||
val map = new HashMap<>(); | ||
map.put("bezirkID", "1234"); | ||
map.put("wahlbezirkID", "1234"); | ||
AuthenticationManager authManager = authentication -> authentication; | ||
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken("username", "password"); | ||
authRequest.setDetails(map); | ||
Authentication auth = authManager.authenticate(authRequest); | ||
SecurityContext context = SecurityContextHolder.createEmptyContext(); | ||
context.setAuthentication(auth); | ||
SecurityContextHolder.setContext(context); | ||
Assertions.assertThat(unitUnderTest.tokenUserBezirkIdMatches("1234", auth)).isTrue(); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...rc/test/java/de/muenchen/wls/common/security/BezirkIDUndWaehlerverzeichnisNummerTest.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,36 @@ | ||
package de.muenchen.wls.common.security; | ||
|
||
import de.muenchen.wls.common.security.domain.BezirkIDUndWaehlerverzeichnisNummer; | ||
import lombok.val; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class BezirkIDUndWaehlerverzeichnisNummerTest { | ||
|
||
@Test | ||
void returnsHash() { | ||
val unitUnderTest = new BezirkIDUndWaehlerverzeichnisNummer(); | ||
unitUnderTest.setWaehlerverzeichnisNummer(Long.valueOf("1")); | ||
unitUnderTest.setWahlbezirkID("2"); | ||
Assertions.assertThat(unitUnderTest.hashCode()).isEqualTo(2512); | ||
} | ||
|
||
@Test | ||
void returnsString() { | ||
val unitUnderTest = new BezirkIDUndWaehlerverzeichnisNummer(); | ||
unitUnderTest.setWaehlerverzeichnisNummer(Long.valueOf("1")); | ||
unitUnderTest.setWahlbezirkID("2"); | ||
Assertions.assertThat(unitUnderTest.toString()).isEqualTo("BezirkIDUndWaehlerverzeichnisNummer{" + "wahlbezirkID='" + 2 + '\'' +", waehlerverzeichnisNummer=" + 1 +'}'); | ||
} | ||
|
||
@Test | ||
void equals() { | ||
val unitUnderTest = new BezirkIDUndWaehlerverzeichnisNummer(); | ||
unitUnderTest.setWaehlerverzeichnisNummer(Long.valueOf("1")); | ||
unitUnderTest.setWahlbezirkID("2"); | ||
val falseObject = new BezirkIDUndWaehlerverzeichnisNummer(); | ||
falseObject.setWaehlerverzeichnisNummer(Long.valueOf("2")); | ||
falseObject.setWahlbezirkID("3"); | ||
Assertions.assertThat(unitUnderTest.equals(falseObject)).isFalse(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
wls-common/security/src/test/java/de/muenchen/wls/common/security/BezirkUndWahlIDTest.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,36 @@ | ||
package de.muenchen.wls.common.security; | ||
|
||
import de.muenchen.wls.common.security.domain.BezirkUndWahlID; | ||
import lombok.val; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class BezirkIDUndWahlIDTest { | ||
|
||
@Test | ||
void returnsHash() { | ||
val unitUnderTest = new BezirkUndWahlID(); | ||
unitUnderTest.setWahlID("1"); | ||
unitUnderTest.setWahlbezirkID("2"); | ||
Assertions.assertThat(unitUnderTest.hashCode()).isEqualTo(2530); | ||
} | ||
|
||
@Test | ||
void returnsString() { | ||
val unitUnderTest = new BezirkUndWahlID(); | ||
unitUnderTest.setWahlID("1"); | ||
unitUnderTest.setWahlbezirkID("2"); | ||
Assertions.assertThat(unitUnderTest.toString()).isEqualTo("de.muenchen.wls.common.security.domain.BezirkUndWahlID{" + "wahlID='" + 1 + '\'' +", wahlbezirkID='" + 2 + '\'' +'}'); | ||
} | ||
|
||
@Test | ||
void equals() { | ||
val unitUnderTest = new BezirkUndWahlID(); | ||
unitUnderTest.setWahlID("1"); | ||
unitUnderTest.setWahlbezirkID("2"); | ||
val falseObject = new BezirkUndWahlID(); | ||
falseObject.setWahlID("2"); | ||
falseObject.setWahlbezirkID("3"); | ||
Assertions.assertThat(unitUnderTest.equals(falseObject)).isFalse(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...c/test/java/de/muenchen/wls/common/security/DummyBezirkIdPermissionEvaluatorImplTest.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,41 @@ | ||
package de.muenchen.wls.common.security; | ||
import de.muenchen.wls.common.security.testultils.LoggerExtension; | ||
import lombok.val; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContext; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
import java.util.HashMap; | ||
|
||
class DummyBezirkIdPermissionEvaluatorImplTest { | ||
|
||
private final DummyBezirkIdPermissionEvaluatorImpl unitUnderTest= new DummyBezirkIdPermissionEvaluatorImpl(); | ||
|
||
@Nested | ||
class TestLoggingEvents { | ||
|
||
@RegisterExtension | ||
public LoggerExtension loggerExtension = new LoggerExtension(); | ||
|
||
@Test | ||
void logInfoMatch() { | ||
val map = new HashMap<>(); | ||
map.put("bezirkID", "1234"); | ||
map.put("wahlbezirkID", "1234"); | ||
AuthenticationManager authManager = authentication -> authentication; | ||
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken("username", "password"); | ||
authRequest.setDetails(map); | ||
Authentication auth = authManager.authenticate(authRequest); | ||
SecurityContext context = SecurityContextHolder.createEmptyContext(); | ||
context.setAuthentication(auth); | ||
SecurityContextHolder.setContext(context); | ||
Assertions.assertThat(unitUnderTest.tokenUserBezirkIdMatches("1234", auth)).isTrue(); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
wls-common/security/src/test/java/de/muenchen/wls/common/security/EncryptionBuilderTest.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,70 @@ | ||
package de.muenchen.wls.common.security; | ||
|
||
import de.muenchen.wls.common.security.testultils.LoggerExtension; | ||
import lombok.val; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import javax.crypto.NoSuchPaddingException; | ||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.SecureRandom; | ||
|
||
|
||
class EncryptionBuilderTest { | ||
|
||
@RegisterExtension | ||
public LoggerExtension loggerExtension = new LoggerExtension(); | ||
|
||
@Nested | ||
class decrypt { | ||
|
||
@Test | ||
void sucessful() throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException { | ||
val aByte = new byte[16]; | ||
val unitUnderTest = new EncryptionBuilder(aByte); | ||
Assertions.assertThat(unitUnderTest.decryptValue("Efl8HLaoqguJ-CkS4r_m_QFD22PuZrDN_59pkXaAFR4=")).isEqualTo("376526723AFDAB3D"); | ||
} | ||
|
||
@Test | ||
void throwBadPadding() throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException { | ||
val aByte = new byte[16]; | ||
val random = new SecureRandom(); | ||
random.nextBytes(aByte); | ||
val unitUnderTest = new EncryptionBuilder(aByte); | ||
try { | ||
unitUnderTest.decryptValue("Efl8HLaoqguJ-CkS4r_m_QFD22PuZrDN_59pkXaAFR4="); | ||
} catch (Exception e) { | ||
Assertions.assertThat(loggerExtension.getFormattedMessages().size()).isEqualTo(1); | ||
} | ||
|
||
} | ||
} | ||
|
||
@Nested | ||
class encrypt { | ||
|
||
@Test | ||
void successful() throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException { | ||
val aByte = new byte[16]; | ||
val unitUnderTest = new EncryptionBuilder(aByte); | ||
Assertions.assertThat(unitUnderTest.encryptValue("376526723AFDAB3D")).isEqualTo("Efl8HLaoqguJ-CkS4r_m_QFD22PuZrDN_59pkXaAFR4="); | ||
} | ||
|
||
@Test | ||
void throwBadPadding() throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException { | ||
val aByte = new byte[16]; | ||
val random = new SecureRandom(); | ||
random.nextBytes(aByte); | ||
val unitUnderTest = new EncryptionBuilder(aByte); | ||
try { | ||
unitUnderTest.encryptValue("376526723AFDAB3D"); | ||
} catch (Exception e) { | ||
Assertions.assertThat(loggerExtension.getFormattedMessages().size()).isEqualTo(1); | ||
} | ||
} | ||
|
||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../security/testultils/LoggerExtension.java → .../security/testultils/LoggerExtension.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
26 changes: 0 additions & 26 deletions
26
...rc/test/java/de/muenchen/wls/common/wls/security/BezirkIDPermissionEvaluatorImplTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.