diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 3f025add..e7083af9 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 diff --git a/.github/workflows/test_bwc.yml b/.github/workflows/test_bwc.yml index d5b31b7a..247b0b18 100644 --- a/.github/workflows/test_bwc.yml +++ b/.github/workflows/test_bwc.yml @@ -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: diff --git a/.github/workflows/test_security.yml b/.github/workflows/test_security.yml index d3db98a0..9b36146c 100644 --- a/.github/workflows/test_security.yml +++ b/.github/workflows/test_security.yml @@ -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 }} diff --git a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java index e225e09f..3453df37 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java @@ -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.", diff --git a/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java index 1e28034c..896f03b0 100644 --- a/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java @@ -128,6 +128,7 @@ protected void doExecute(Task task, WorkflowRequest request, ActionListener 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(), diff --git a/src/main/java/org/opensearch/flowframework/util/EncryptorUtils.java b/src/main/java/org/opensearch/flowframework/util/EncryptorUtils.java index c660b76e..51a30175 100644 --- a/src/main/java/org/opensearch/flowframework/util/EncryptorUtils.java +++ b/src/main/java/org/opensearch/flowframework/util/EncryptorUtils.java @@ -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); diff --git a/src/test/java/org/opensearch/flowframework/FlowFrameworkTenantAwareRestTestCase.java b/src/test/java/org/opensearch/flowframework/FlowFrameworkTenantAwareRestTestCase.java index 72126c8d..c76ba6bb 100644 --- a/src/test/java/org/opensearch/flowframework/FlowFrameworkTenantAwareRestTestCase.java +++ b/src/test/java/org/opensearch/flowframework/FlowFrameworkTenantAwareRestTestCase.java @@ -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 { diff --git a/src/test/java/org/opensearch/flowframework/rest/RestWorkflowTenantAwareIT.java b/src/test/java/org/opensearch/flowframework/rest/RestWorkflowTenantAwareIT.java index ba9f3383..5eea23fe 100644 --- a/src/test/java/org/opensearch/flowframework/rest/RestWorkflowTenantAwareIT.java +++ b/src/test/java/org/opensearch/flowframework/rest/RestWorkflowTenantAwareIT.java @@ -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)); diff --git a/src/test/java/org/opensearch/flowframework/util/RestActionUtilsTests.java b/src/test/java/org/opensearch/flowframework/util/RestActionUtilsTests.java index 6d3be200..36ff2cc1 100644 --- a/src/test/java/org/opensearch/flowframework/util/RestActionUtilsTests.java +++ b/src/test/java/org/opensearch/flowframework/util/RestActionUtilsTests.java @@ -15,7 +15,6 @@ 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; @@ -23,7 +22,7 @@ import java.util.Map; public class RestActionUtilsTests extends OpenSearchTestCase { - @Test + public void testGetTenantID() { String tenantId = "test-tenant"; Map> headers = new HashMap<>(); @@ -34,7 +33,6 @@ public void testGetTenantID() { Assert.assertEquals(tenantId, actualTenantID); } - @Test public void testGetTenantID_NullTenantID() { Map> headers = new HashMap<>(); headers.put(CommonValue.TENANT_ID_HEADER, Collections.singletonList(null)); @@ -50,7 +48,6 @@ public void testGetTenantID_NullTenantID() { } } - @Test public void testGetTenantID_NoMultiTenancy() { String tenantId = "test-tenant"; Map> headers = new HashMap<>(); @@ -61,7 +58,6 @@ public void testGetTenantID_NoMultiTenancy() { Assert.assertNull(tenantID); } - @Test public void testGetTenantID_EmptyTenantIDList() { Map> headers = new HashMap<>(); headers.put(CommonValue.TENANT_ID_HEADER, Collections.emptyList()); @@ -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> headers = new HashMap<>(); RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withHeaders(headers).build(); @@ -88,7 +83,6 @@ public void testGetTenantID_MissingTenantIDHeader() { assertEquals("Tenant ID header is missing", exception.getMessage()); } - @Test public void testGetTenantID_MultipleValues() { Map> headers = new HashMap<>(); headers.put(CommonValue.TENANT_ID_HEADER, List.of("tenant1", "tenant2")); @@ -98,7 +92,6 @@ public void testGetTenantID_MultipleValues() { assertEquals("tenant1", actualTenantID); } - @Test public void testGetTenantID_EmptyStringTenantID() { Map> headers = new HashMap<>(); headers.put(CommonValue.TENANT_ID_HEADER, Collections.singletonList("")); diff --git a/src/test/java/org/opensearch/flowframework/util/TenantAwareHelperTests.java b/src/test/java/org/opensearch/flowframework/util/TenantAwareHelperTests.java index 750094a6..a6fbc7d1 100644 --- a/src/test/java/org/opensearch/flowframework/util/TenantAwareHelperTests.java +++ b/src/test/java/org/opensearch/flowframework/util/TenantAwareHelperTests.java @@ -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; @@ -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); @@ -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); @@ -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)); }