You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WireMock enables testing with the Okta Java SDK by providing a mock HTTP server that simulates Okta's API endpoints over HTTPS. This eliminates the need to hit actual Okta servers during development and testing, removing rate limit concerns and enabling rapid iteration.
812
-
813
-
### Problem
814
-
815
-
The Okta SDK requires HTTPS connections, and when using WireMock with self-signed certificates, the SDK's HTTP client must be configured to trust the mock server's certificate. This section demonstrates the complete setup.
816
-
817
-
### Solution Architecture
818
-
819
-
The solution consists of three components:
820
-
821
-
1. **Self-Signed Certificate Generation**: Automatically generates a JKS keystore with a self-signed certificate
822
-
2. **WireMock HTTPS Configuration**: Configures WireMock server to use the certificate
823
-
3. **Custom SSL Context**: Configures the Okta SDK's HTTP client to trust the certificate
824
-
825
-
### Implementation
826
-
827
-
#### Step 1: Automatic Certificate Generation
828
-
829
-
The test setup automatically generates a self-signed certificate on first run:
throw new RuntimeException("Failed to generate WireMock keystore");
844
-
}
845
-
}
846
-
```
847
-
848
-
The certificate is generated once and reused for subsequent test runs. The `.gitignore` file excludes the keystore from version control to maintain security best practices.
849
-
850
-
#### Step 2: Configure WireMock Server
851
-
852
-
Start WireMock on HTTPS port 8443 using the generated certificate:
853
-
854
-
```java
855
-
wireMockServer = new WireMockServer(
856
-
WireMockConfiguration.wireMockConfig()
857
-
.httpsPort(8443)
858
-
.keystorePath(keystorePath)
859
-
.keystorePassword("password")
860
-
);
861
-
wireMockServer.start();
862
-
```
863
-
864
-
#### Step 3: Create Custom SSL Context
865
-
866
-
Load the keystore and configure an SSL context that trusts the self-signed certificate:
WireMock can be configured to serve HTTPS with a self-signed certificate and custom KeyStore. The SDK's HTTP client can be configured with a custom SSLContext and TrustManager to accept the certificate. This implementation demonstrates both: automatic self-signed certificate generation, WireMock HTTPS configuration, and SDK HTTP client setup with a custom TrustManager. It also uses dynamic port allocation for thread-safe parallel test execution.
964
810
965
811
### Running the Tests
966
812
967
-
Execute the integration tests with:
968
-
969
813
```bash
970
814
mvn test -Dtest=WireMockOktaClientTest -pl integration-tests
971
815
```
972
816
973
-
Expected output:
974
-
975
-
```
976
-
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
977
-
```
978
-
979
-
### Prerequisites
980
-
981
-
- Java Development Kit (JDK) 8 or later
982
-
- Apache Maven 3.6 or later
983
-
- keytool (included with JDK)
984
-
985
-
### Troubleshooting
986
-
987
-
**Port Already in Use**
988
-
989
-
If port 8443 is in use, the dynamic port allocation in the current implementation automatically selects an available port. Ensure you pass the dynamically assigned port to the client configuration.
990
-
991
-
**Certificate Trust Issues**
992
-
993
-
Verify that the keystore file is generated and accessible:
994
-
995
-
```bash
996
-
ls -la wiremock-keystore.jks
997
-
```
998
-
999
-
If the file is missing or corrupted, delete it and run tests again to regenerate.
1000
-
1001
-
**keytool Not Found**
1002
-
1003
-
keytool is included with the JDK. Ensure JAVA_HOME is properly configured:
1004
-
1005
-
```bash
1006
-
echo $JAVA_HOME
1007
-
```
817
+
See the complete implementation in `integration-tests/src/test/java/com/okta/sdk/tests/WireMockOktaClientTest.java`.
0 commit comments