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 8cd5b8f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 19 deletions.
36 changes: 35 additions & 1 deletion .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
./gradlew integTest -PnumNodes=3 -Dtests.rest.tenantaware=true
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 -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 @@ -420,7 +420,7 @@ private String hashString(String input) {
MessageDigest digest = MessageDigest.getInstance("SHA-256");

Check warning on line 420 in src/main/java/org/opensearch/flowframework/util/EncryptorUtils.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/util/EncryptorUtils.java#L420

Added line #L420 was not covered by tests

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

Check warning on line 423 in src/main/java/org/opensearch/flowframework/util/EncryptorUtils.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/util/EncryptorUtils.java#L423

Added line #L423 was not covered by tests

// Convert the byte array to a Base64 encoded string
return Base64.getUrlEncoder().encodeToString(hashBytes);

Check warning on line 426 in src/main/java/org/opensearch/flowframework/util/EncryptorUtils.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/util/EncryptorUtils.java#L426

Added line #L426 was not covered by tests
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 @@ -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 8cd5b8f

Please sign in to comment.