Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
FIT-Connect-SDK - Java
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FIT-Connect
FIT-Connect-SDK - Java
Commits
0f44ada3
Commit
0f44ada3
authored
1 year ago
by
Martin Vogel
Browse files
Options
Downloads
Patches
Plain Diff
refactor(#664): add more tests
parent
4fc75111
No related branches found
No related tags found
1 merge request
!211
#664 Test JWK Generator
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tools/pom.xml
+5
-0
5 additions, 0 deletions
tools/pom.xml
tools/src/test/java/dev/fitko/fitconnect/sdk/tools/JWKGeneratorTest.java
+57
-0
57 additions, 0 deletions
...java/dev/fitko/fitconnect/sdk/tools/JWKGeneratorTest.java
with
62 additions
and
0 deletions
tools/pom.xml
+
5
−
0
View file @
0f44ada3
...
@@ -40,6 +40,11 @@
...
@@ -40,6 +40,11 @@
<artifactId>
hamcrest-all
</artifactId>
<artifactId>
hamcrest-all
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
dev.fitko.fitconnect.sdk
</groupId>
<artifactId>
core
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
This diff is collapsed.
Click to expand it.
tools/src/test/java/dev/fitko/fitconnect/sdk/tools/JWKGeneratorTest.java
+
57
−
0
View file @
0f44ada3
...
@@ -5,17 +5,23 @@ import com.nimbusds.jose.JWSAlgorithm;
...
@@ -5,17 +5,23 @@ import com.nimbusds.jose.JWSAlgorithm;
import
com.nimbusds.jose.jwk.JWK
;
import
com.nimbusds.jose.jwk.JWK
;
import
com.nimbusds.jose.jwk.KeyOperation
;
import
com.nimbusds.jose.jwk.KeyOperation
;
import
com.nimbusds.jose.jwk.KeyType
;
import
com.nimbusds.jose.jwk.KeyType
;
import
dev.fitko.fitconnect.core.crypto.JWECryptoService
;
import
dev.fitko.fitconnect.jwkvalidator.JWKValidator
;
import
dev.fitko.fitconnect.jwkvalidator.exceptions.LogLevel
;
import
org.hamcrest.CoreMatchers
;
import
org.hamcrest.CoreMatchers
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Map
;
import
java.util.Map
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
contains
;
import
static
org
.
hamcrest
.
Matchers
.
contains
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertDoesNotThrow
;
class
JWKGeneratorTest
{
class
JWKGeneratorTest
{
...
@@ -82,6 +88,42 @@ class JWKGeneratorTest {
...
@@ -82,6 +88,42 @@ class JWKGeneratorTest {
assertThat
(
keyParams
.
get
(
"qi"
),
CoreMatchers
.
is
(
CoreMatchers
.
notNullValue
()));
assertThat
(
keyParams
.
get
(
"qi"
),
CoreMatchers
.
is
(
CoreMatchers
.
notNullValue
()));
}
}
@Test
void
testEncryptionAndDecryption
()
{
// Given
final
JWKPair
encryptionKeyPair
=
underTest
.
generateEncryptionKeyPair
(
4096
);
final
JWK
publicKey
=
encryptionKeyPair
.
getPublicKey
();
final
JWK
privateKey
=
encryptionKeyPair
.
getPrivateKey
();
final
var
data
=
"test string to encrypt"
;
// When
final
JWECryptoService
cryptoService
=
new
JWECryptoService
(
null
);
final
String
encryptedData
=
cryptoService
.
encryptBytes
(
publicKey
.
toRSAKey
(),
data
.
getBytes
(
StandardCharsets
.
UTF_8
));
final
byte
[]
decryptedData
=
cryptoService
.
decryptToBytes
(
privateKey
.
toRSAKey
(),
encryptedData
);
// Then
assertThat
(
data
,
is
(
new
String
(
decryptedData
)));
}
@Test
void
testPublicEncryptionKeyValidationWithCorrectKeyLength
()
{
// Given
final
JWKPair
encryptionKeyPair
=
underTest
.
generateEncryptionKeyPair
(
4096
);
final
JWK
publicKey
=
encryptionKeyPair
.
getPublicKey
();
// Then
assertDoesNotThrow
(()
->
JWKValidator
.
withoutX5CValidation
()
.
withErrorLogLevel
(
LogLevel
.
ERROR
)
.
build
()
.
validate
(
publicKey
.
toRSAKey
(),
KeyOperation
.
WRAP_KEY
));
}
@Test
@Test
void
testPublicSignatureVerificationKey
()
{
void
testPublicSignatureVerificationKey
()
{
...
@@ -105,6 +147,21 @@ class JWKGeneratorTest {
...
@@ -105,6 +147,21 @@ class JWKGeneratorTest {
}
}
@Test
void
testPublicSignatureKeyValidation
()
{
// Given
final
JWKPair
signatureKeyPair
=
underTest
.
generateSignatureKeyPair
(
4096
);
final
JWK
publicKey
=
signatureKeyPair
.
getPublicKey
();
// Then
assertDoesNotThrow
(()
->
JWKValidator
.
withoutX5CValidation
()
.
withErrorLogLevel
(
LogLevel
.
ERROR
)
.
build
()
.
validate
(
publicKey
.
toRSAKey
(),
KeyOperation
.
VERIFY
));
}
@Test
@Test
void
testPrivateSigningKey
()
{
void
testPrivateSigningKey
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment