-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd8ae13
commit a60f851
Showing
8 changed files
with
290 additions
and
9 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
45 changes: 45 additions & 0 deletions
45
...main/java/neo4j/org/testkit/backend/messages/requests/ClientCertificateProviderClose.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,45 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [https://neo4j.com] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package neo4j.org.testkit.backend.messages.requests; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import neo4j.org.testkit.backend.TestkitState; | ||
import neo4j.org.testkit.backend.messages.responses.ClientCertificateProvider; | ||
import neo4j.org.testkit.backend.messages.responses.TestkitResponse; | ||
|
||
@Setter | ||
@Getter | ||
public class ClientCertificateProviderClose extends AbstractBasicTestkitRequest { | ||
private AuthTokenManagerCloseBody data; | ||
|
||
@Override | ||
protected TestkitResponse processAndCreateResponse(TestkitState testkitState) { | ||
testkitState.removeClientCertificateManager(data.getId()); | ||
return ClientCertificateProvider.builder() | ||
.data(ClientCertificateProvider.ClientCertificateProviderBody.builder() | ||
.id(data.getId()) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
@Setter | ||
@Getter | ||
public static class AuthTokenManagerCloseBody { | ||
private String id; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../java/neo4j/org/testkit/backend/messages/requests/ClientCertificateProviderCompleted.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,39 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [https://neo4j.com] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package neo4j.org.testkit.backend.messages.requests; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Setter | ||
@Getter | ||
public class ClientCertificateProviderCompleted implements TestkitCallbackResult { | ||
private ClientCertificateProviderCompletedBody data; | ||
|
||
@Override | ||
public String getCallbackId() { | ||
return data.getRequestId(); | ||
} | ||
|
||
@Setter | ||
@Getter | ||
public static class ClientCertificateProviderCompletedBody { | ||
private String requestId; | ||
private ClientCertificate clientCertificate; | ||
private boolean hasUpdate; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...c/main/java/neo4j/org/testkit/backend/messages/requests/NewClientCertificateProvider.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,93 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [https://neo4j.com] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package neo4j.org.testkit.backend.messages.requests; | ||
|
||
import java.nio.file.Paths; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import neo4j.org.testkit.backend.TestkitState; | ||
import neo4j.org.testkit.backend.messages.responses.ClientCertificateProvider; | ||
import neo4j.org.testkit.backend.messages.responses.ClientCertificateProviderRequest; | ||
import neo4j.org.testkit.backend.messages.responses.TestkitCallback; | ||
import neo4j.org.testkit.backend.messages.responses.TestkitResponse; | ||
import org.neo4j.driver.ClientCertificate; | ||
import org.neo4j.driver.ClientCertificateManager; | ||
import org.neo4j.driver.ClientCertificates; | ||
|
||
@Setter | ||
@Getter | ||
public class NewClientCertificateProvider extends AbstractBasicTestkitRequest { | ||
private NewClientCertificateProviderBody data; | ||
|
||
@Override | ||
protected TestkitResponse processAndCreateResponse(TestkitState testkitState) { | ||
var id = testkitState.newId(); | ||
testkitState.addClientCertificateManager(id, new TestkitClientCertificateManager(id, testkitState)); | ||
return ClientCertificateProvider.builder() | ||
.data(ClientCertificateProvider.ClientCertificateProviderBody.builder() | ||
.id(id) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
private record TestkitClientCertificateManager(String id, TestkitState testkitState) | ||
implements ClientCertificateManager { | ||
@Override | ||
public CompletionStage<ClientCertificate> getCertificate() { | ||
var callbackId = testkitState.newId(); | ||
|
||
var callback = ClientCertificateProviderRequest.builder() | ||
.data(ClientCertificateProviderRequest.ClientCertificateProviderRequestBody.builder() | ||
.clientCertificateProviderId(id) | ||
.build()) | ||
.build(); | ||
|
||
ClientCertificate clientCertificate = null; | ||
var callbackStage = dispatchTestkitCallback(testkitState, callback); | ||
try { | ||
var response = callbackStage.toCompletableFuture().get(); | ||
if (response instanceof ClientCertificateProviderCompleted clientCertificateComplete) { | ||
var data = clientCertificateComplete.getData(); | ||
var certificateData = data.getClientCertificate().getData(); | ||
var hasUpdate = data.isHasUpdate(); | ||
clientCertificate = ClientCertificates.of( | ||
Paths.get(certificateData.getCertfile()).toFile(), | ||
Paths.get(certificateData.getKeyfile()).toFile(), | ||
certificateData.getPassword(), | ||
hasUpdate); | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException("Unexpected failure during Testkit callback", e); | ||
} | ||
return CompletableFuture.completedStage(clientCertificate); | ||
} | ||
|
||
private CompletionStage<TestkitCallbackResult> dispatchTestkitCallback( | ||
TestkitState testkitState, TestkitCallback response) { | ||
var future = new CompletableFuture<TestkitCallbackResult>(); | ||
testkitState.getCallbackIdToFuture().put(response.getCallbackId(), future); | ||
testkitState.getResponseWriter().accept(response); | ||
return future; | ||
} | ||
} | ||
|
||
@Setter | ||
@Getter | ||
public static class NewClientCertificateProviderBody {} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...src/main/java/neo4j/org/testkit/backend/messages/responses/ClientCertificateProvider.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,37 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [https://neo4j.com] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package neo4j.org.testkit.backend.messages.responses; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class ClientCertificateProvider implements TestkitResponse { | ||
private ClientCertificateProviderBody data; | ||
|
||
@Override | ||
public String testkitName() { | ||
return "ClientCertificateProvider"; | ||
} | ||
|
||
@Getter | ||
@Builder | ||
public static class ClientCertificateProviderBody { | ||
private String id; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...n/java/neo4j/org/testkit/backend/messages/responses/ClientCertificateProviderRequest.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,43 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [https://neo4j.com] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package neo4j.org.testkit.backend.messages.responses; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class ClientCertificateProviderRequest implements TestkitCallback { | ||
private ClientCertificateProviderRequestBody data; | ||
|
||
@Override | ||
public String getCallbackId() { | ||
return data.getId(); | ||
} | ||
|
||
@Override | ||
public String testkitName() { | ||
return "ClientCertificateProviderRequest"; | ||
} | ||
|
||
@Getter | ||
@Builder | ||
public static class ClientCertificateProviderRequestBody { | ||
private String id; | ||
private String clientCertificateProviderId; | ||
} | ||
} |