forked from smallrye/smallrye-certificate-generator
-
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.
Merge pull request smallrye#5 from ozangunalp/main
Return `CertificateFiles` from generate and make those injectable in Junit5 extension
- Loading branch information
Showing
9 changed files
with
430 additions
and
27 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...tor-junit5/src/main/java/me/escoffier/certs/junit5/CertificateFilesArgumentsProvider.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,27 @@ | ||
package me.escoffier.certs.junit5; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.params.provider.AnnotationBasedArgumentsProvider; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
|
||
import me.escoffier.certs.CertificateFiles; | ||
|
||
public class CertificateFilesArgumentsProvider extends AnnotationBasedArgumentsProvider<CertificatesSource> { | ||
@Override | ||
protected Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext, CertificatesSource certificatesSource) { | ||
CertificateGenerationExtension extension = CertificateGenerationExtension.getInstance(extensionContext); | ||
Stream<CertificateFiles> stream = extension.certificateFiles.stream(); | ||
if (certificatesSource.names().length > 0) { | ||
stream = stream.filter(certificateFiles -> Arrays.stream(certificatesSource.names()) | ||
.anyMatch(name -> name.equals(certificateFiles.name()))); | ||
} | ||
if (certificatesSource.formats().length > 0) { | ||
stream = stream.filter(certificateFiles -> Arrays.stream(certificatesSource.formats()) | ||
.anyMatch(name -> name.equals(certificateFiles.format()))); | ||
} | ||
return stream.map(Arguments::of); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
certificate-generator-junit5/src/main/java/me/escoffier/certs/junit5/CertificatesSource.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,19 @@ | ||
package me.escoffier.certs.junit5; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.junit.jupiter.params.provider.ArgumentsSource; | ||
|
||
import me.escoffier.certs.Format; | ||
|
||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ArgumentsSource(CertificateFilesArgumentsProvider.class) | ||
public @interface CertificatesSource { | ||
String[] names() default {}; | ||
|
||
Format[] formats() default {}; | ||
} |
19 changes: 19 additions & 0 deletions
19
certificate-generator/src/main/java/me/escoffier/certs/CertificateFiles.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,19 @@ | ||
package me.escoffier.certs; | ||
|
||
import java.nio.file.Path; | ||
|
||
public sealed interface CertificateFiles permits JksCertificateFiles, PemCertificateFiles, Pkcs12CertificateFiles { | ||
|
||
String name(); | ||
|
||
Format format(); | ||
|
||
Path root(); | ||
|
||
boolean client(); | ||
|
||
String password(); | ||
|
||
Path trustStore(); | ||
|
||
} |
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
84 changes: 84 additions & 0 deletions
84
certificate-generator/src/main/java/me/escoffier/certs/JksCertificateFiles.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,84 @@ | ||
package me.escoffier.certs; | ||
|
||
import java.nio.file.Path; | ||
|
||
public final class JksCertificateFiles implements CertificateFiles { | ||
|
||
private final Path root; | ||
private final String name; | ||
private final boolean client; | ||
private final String password; | ||
|
||
private final Path keyStoreFile; | ||
private final Path trustStoreFile; | ||
private final Path clientKeyStoreFile; | ||
private final Path serverTrustStoreFile; | ||
|
||
public JksCertificateFiles(Path root, String name, boolean client, String password) { | ||
this.root = root; | ||
this.name = name; | ||
this.client = client; | ||
this.password = password; | ||
this.keyStoreFile = root.resolve(name + "-keystore." + format().extension()); | ||
this.trustStoreFile = root.resolve(name + (client ? "-client" : "") + "-truststore." + format().extension()); | ||
this.clientKeyStoreFile = root.resolve(name + "-client-keystore." + format().extension()); | ||
this.serverTrustStoreFile = root.resolve(name + "-server-truststore." + format().extension()); | ||
} | ||
|
||
@Override | ||
public Format format() { | ||
return Format.JKS; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Path root() { | ||
return root; | ||
} | ||
|
||
@Override | ||
public boolean client() { | ||
return client; | ||
} | ||
|
||
@Override | ||
public String password() { | ||
return password; | ||
} | ||
|
||
@Override | ||
public Path trustStore() { | ||
return client ? serverTrustStoreFile: trustStoreFile; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JksCertificateFiles{" + | ||
"root=" + root + | ||
", name='" + name + '\'' + | ||
", client=" + client + | ||
", password='" + password + '\'' + | ||
'}'; | ||
} | ||
|
||
public Path keyStoreFile() { | ||
return keyStoreFile; | ||
} | ||
|
||
public Path trustStoreFile() { | ||
return trustStoreFile; | ||
} | ||
|
||
public Path clientKeyStoreFile() { | ||
return clientKeyStoreFile; | ||
} | ||
|
||
public Path serverTrustStoreFile() { | ||
return serverTrustStoreFile; | ||
} | ||
|
||
} |
Oops, something went wrong.