forked from elastic/elasticsearch
-
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 branch 'main' into fix-operator-privilege-IT
- Loading branch information
Showing
17 changed files
with
552 additions
and
154 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
apply plugin: 'elasticsearch.java' | ||
|
||
description = 'Fixture for emulating the Security Token Service (STS) running in AWS' | ||
|
||
dependencies { | ||
api project(':server') | ||
api("junit:junit:${versions.junit}") { | ||
transitive = false | ||
} | ||
api project(':test:framework') | ||
} |
64 changes: 64 additions & 0 deletions
64
test/fixtures/aws-sts-fixture/src/main/java/fixture/aws/sts/AwsStsHttpFixture.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,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
package fixture.aws.sts; | ||
|
||
import com.sun.net.httpserver.HttpHandler; | ||
import com.sun.net.httpserver.HttpServer; | ||
|
||
import org.junit.rules.ExternalResource; | ||
|
||
import java.net.InetAddress; | ||
import java.net.InetSocketAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.Objects; | ||
import java.util.function.BiConsumer; | ||
|
||
public class AwsStsHttpFixture extends ExternalResource { | ||
|
||
private HttpServer server; | ||
|
||
private final BiConsumer<String, String> newCredentialsConsumer; | ||
private final String webIdentityToken; | ||
|
||
public AwsStsHttpFixture(BiConsumer<String, String> newCredentialsConsumer, String webIdentityToken) { | ||
this.newCredentialsConsumer = Objects.requireNonNull(newCredentialsConsumer); | ||
this.webIdentityToken = Objects.requireNonNull(webIdentityToken); | ||
} | ||
|
||
protected HttpHandler createHandler() { | ||
return new AwsStsHttpHandler(newCredentialsConsumer, webIdentityToken); | ||
} | ||
|
||
public String getAddress() { | ||
return "http://" + server.getAddress().getHostString() + ":" + server.getAddress().getPort(); | ||
} | ||
|
||
public void stop(int delay) { | ||
server.stop(delay); | ||
} | ||
|
||
protected void before() throws Throwable { | ||
server = HttpServer.create(resolveAddress(), 0); | ||
server.createContext("/", Objects.requireNonNull(createHandler())); | ||
server.start(); | ||
} | ||
|
||
@Override | ||
protected void after() { | ||
stop(0); | ||
} | ||
|
||
private static InetSocketAddress resolveAddress() { | ||
try { | ||
return new InetSocketAddress(InetAddress.getByName("localhost"), 0); | ||
} catch (UnknownHostException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.