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
Merge requests
!211
#664 Test JWK Generator
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
#664 Test JWK Generator
feature/664-test-cert-generator
into
main
Overview
0
Commits
27
Pipelines
0
Changes
2
Merged
Martin Vogel
requested to merge
feature/664-test-cert-generator
into
main
1 year ago
Overview
0
Commits
27
Pipelines
0
Changes
2
Expand
Closes
planning#664 (closed)
0
0
Merge request reports
Viewing commit
0f44ada3
Prev
Next
Show latest version
2 files
+
62
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
0f44ada3
refactor(#664): add more tests
· 0f44ada3
Martin Vogel
authored
1 year ago
tools/src/test/java/dev/fitko/fitconnect/sdk/tools/JWKGeneratorTest.java
+
57
−
0
Options
@@ -5,17 +5,23 @@ import com.nimbusds.jose.JWSAlgorithm;
import
com.nimbusds.jose.jwk.JWK
;
import
com.nimbusds.jose.jwk.KeyOperation
;
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.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Map
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
contains
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertDoesNotThrow
;
class
JWKGeneratorTest
{
@@ -82,6 +88,42 @@ class JWKGeneratorTest {
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
void
testPublicSignatureVerificationKey
()
{
@@ -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
void
testPrivateSigningKey
()
{
Loading