Skip to content

Commit

Permalink
Fix some CI
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Dec 27, 2024
1 parent af82c27 commit 090727f
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 18 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,38 @@ jobs:
- name: Build and Run Tests
run: |
./gradlew integTest -PnumNodes=3
integTenantAwareTest:
needs: [spotless, javadoc]
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
java: [21]
name: Tenant Aware Integ Test JDK${{ matrix.java }}, ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
# TEMPORARY until this is on Maven
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
- name: Checkout Metadata Client
uses: actions/checkout@v4
with:
repository: dbwiddis/opensearch-remote-metadata-sdk
ref: main
path: opensearch-remote-metadata-sdk
- name: Publish to maven local
working-directory: opensearch-remote-metadata-sdk
run: ./gradlew publishToMavenLocal
# end TEMPORARY code
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: temurin
- name: Build and Run Tests
run: |
./gradlew integTest -PnumNodes=3 -Dtests.rest.tenantaware=true
16 changes: 16 additions & 0 deletions .github/workflows/test_bwc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ jobs:
runs-on: ubuntu-latest

steps:
# TEMPORARY until this is on Maven
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
- name: Checkout Metadata Client
uses: actions/checkout@v4
with:
repository: dbwiddis/opensearch-remote-metadata-sdk
ref: main
path: opensearch-remote-metadata-sdk
- name: Publish to maven local
working-directory: opensearch-remote-metadata-sdk
run: ./gradlew publishToMavenLocal
# end TEMPORARY code
- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v4
with:
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/test_security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ jobs:
options: --user root

steps:
# TEMPORARY until this is on Maven
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
- name: Checkout Metadata Client
uses: actions/checkout@v4
with:
repository: dbwiddis/opensearch-remote-metadata-sdk
ref: main
path: opensearch-remote-metadata-sdk
- name: Publish to maven local
working-directory: opensearch-remote-metadata-sdk
run: ./gradlew publishToMavenLocal
# end TEMPORARY code
- name: Checkout Flow Framework
uses: actions/checkout@v3
- name: Setup Java ${{ matrix.java }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
new BytesRestResponse(ffe.getRestStatus(), ffe.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS))
);
}
logger.error("DEBUG: Tenant Aware? " + flowFrameworkSettings.isMultiTenancyEnabled());
String tenantId = RestActionUtils.getTenantID(flowFrameworkSettings.isMultiTenancyEnabled(), request);
logger.error("DEBUG: Tenant ID: " + tenantId);
if (!provision && !params.isEmpty()) {
FlowFrameworkException ffe = new FlowFrameworkException(
"Only the parameters " + request.consumedParams() + " are permitted unless the provision parameter is set to true.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ protected void doExecute(Task task, WorkflowRequest request, ActionListener<Work
if (!TenantAwareHelper.validateTenantId(flowFrameworkSettings.isMultiTenancyEnabled(), tenantId, listener)) {
return;
}
logger.error("DEBUG: Tenant Id: " + tenantId);
User user = getUserContext(client);
String workflowId = request.getWorkflowId();
try {
Expand Down Expand Up @@ -219,6 +220,7 @@ private void resolveUserAndExecute(
* @param listener the action listener
*/
private void createExecute(WorkflowRequest request, User user, String tenantId, ActionListener<WorkflowResponse> listener) {
logger.error("DEBUG: Tenant Ids: " + tenantId + " as param, " + request.getTemplate().getTenantId() + " in template");
Instant creationTime = Instant.now();
Template templateWithUser = new Template(
request.getTemplate().name(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private String hashString(String input) {
MessageDigest digest = MessageDigest.getInstance("SHA-256");

// Perform the hashing and get the byte array
byte[] hashBytes = digest.digest(input.getBytes());
byte[] hashBytes = digest.digest(input.getBytes(StandardCharsets.UTF_8));

// Convert the byte array to a Base64 encoded string
return Base64.getUrlEncoder().encodeToString(hashBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static org.opensearch.common.xcontent.XContentType.JSON;
import static org.opensearch.flowframework.common.CommonValue.*;
import static org.opensearch.flowframework.common.FlowFrameworkSettings.*;
import static org.opensearch.flowframework.common.CommonValue.TENANT_ID_HEADER;
import static org.opensearch.flowframework.common.FlowFrameworkSettings.FLOW_FRAMEWORK_MULTI_TENANCY_ENABLED;

public abstract class FlowFrameworkTenantAwareRestTestCase extends FlowFrameworkRestTestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void testWorkflowCRUD() throws Exception {
response = makeRequest(tenantRequest, GET, WORKFLOW_PATH + workflowId);
assertOK(response);
map = responseToMap(response);
logger.error("DEBUG: " + map.toString());
assertEquals("noop", map.get("name"));
if (multiTenancyEnabled) {
assertEquals(tenantId, map.get(TENANT_ID_FIELD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.test.rest.FakeRestRequest;
import org.junit.Assert;
import org.junit.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RestActionUtilsTests extends OpenSearchTestCase {
@Test

public void testGetTenantID() {
String tenantId = "test-tenant";
Map<String, List<String>> headers = new HashMap<>();
Expand All @@ -34,7 +33,6 @@ public void testGetTenantID() {
Assert.assertEquals(tenantId, actualTenantID);
}

@Test
public void testGetTenantID_NullTenantID() {
Map<String, List<String>> headers = new HashMap<>();
headers.put(CommonValue.TENANT_ID_HEADER, Collections.singletonList(null));
Expand All @@ -50,7 +48,6 @@ public void testGetTenantID_NullTenantID() {
}
}

@Test
public void testGetTenantID_NoMultiTenancy() {
String tenantId = "test-tenant";
Map<String, List<String>> headers = new HashMap<>();
Expand All @@ -61,7 +58,6 @@ public void testGetTenantID_NoMultiTenancy() {
Assert.assertNull(tenantID);
}

@Test
public void testGetTenantID_EmptyTenantIDList() {
Map<String, List<String>> headers = new HashMap<>();
headers.put(CommonValue.TENANT_ID_HEADER, Collections.emptyList());
Expand All @@ -75,7 +71,6 @@ public void testGetTenantID_EmptyTenantIDList() {
assertEquals("Tenant ID header is present but has no value", exception.getMessage());
}

@Test
public void testGetTenantID_MissingTenantIDHeader() {
Map<String, List<String>> headers = new HashMap<>();
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withHeaders(headers).build();
Expand All @@ -88,7 +83,6 @@ public void testGetTenantID_MissingTenantIDHeader() {
assertEquals("Tenant ID header is missing", exception.getMessage());
}

@Test
public void testGetTenantID_MultipleValues() {
Map<String, List<String>> headers = new HashMap<>();
headers.put(CommonValue.TENANT_ID_HEADER, List.of("tenant1", "tenant2"));
Expand All @@ -98,7 +92,6 @@ public void testGetTenantID_MultipleValues() {
assertEquals("tenant1", actualTenantID);
}

@Test
public void testGetTenantID_EmptyStringTenantID() {
Map<String, List<String>> headers = new HashMap<>();
headers.put(CommonValue.TENANT_ID_HEADER, Collections.singletonList(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.opensearch.core.rest.RestStatus;
import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.junit.Before;
import org.junit.Test;

import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
Expand All @@ -32,7 +31,6 @@ public void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
public void testValidateTenantId_MultiTenancyEnabled_TenantIdNull() {
boolean result = TenantAwareHelper.validateTenantId(true, null, actionListener);
assertFalse(result);
Expand All @@ -43,17 +41,14 @@ public void testValidateTenantId_MultiTenancyEnabled_TenantIdNull() {
assert exception.getMessage().equals("You don't have permission to access this resource");
}

@Test
public void testValidateTenantId_MultiTenancyEnabled_TenantIdPresent() {
assertTrue(TenantAwareHelper.validateTenantId(true, "_tenant_id", actionListener));
}

@Test
public void testValidateTenantId_MultiTenancyDisabled() {
assertTrue(TenantAwareHelper.validateTenantId(false, null, actionListener));
}

@Test
public void testValidateTenantResource_MultiTenancyEnabled_TenantIdMismatch() {
boolean result = TenantAwareHelper.validateTenantResource(true, null, "different_tenant_id", actionListener);
assertFalse(result);
Expand All @@ -64,12 +59,10 @@ public void testValidateTenantResource_MultiTenancyEnabled_TenantIdMismatch() {
assert exception.getMessage().equals("You don't have permission to access this resource");
}

@Test
public void testValidateTenantResource_MultiTenancyEnabled_TenantIdMatch() {
assertTrue(TenantAwareHelper.validateTenantResource(true, "_tenant_id", "_tenant_id", actionListener));
}

@Test
public void testValidateTenantResource_MultiTenancyDisabled() {
assertTrue(TenantAwareHelper.validateTenantResource(false, "_tenant_id", "different_tenant_id", actionListener));
}
Expand Down

0 comments on commit 090727f

Please sign in to comment.