Skip to content

Commit

Permalink
chore(test): fix quay tests and improve RBAC testing for scaffolding (#…
Browse files Browse the repository at this point in the history
…2223)

* Fix quay plugin and improve Test catalog-entity create for RBAC

* Fix quay plugin and improve Test catalog-entity create for RBAC

RHIDP-826 RBAC testing for scaffolding
RHIDP-3656 e2e Quay tests are failing

Signed-off-by: Gustavo Lira <[email protected]>

* Fix quay plugin and improve Test catalog-entity create for RBAC

RHIDP-826 RBAC testing for scaffolding
RHIDP-3656 e2e Quay tests are failing

Signed-off-by: Gustavo Lira <[email protected]>

---------

Signed-off-by: Gustavo Lira <[email protected]>
  • Loading branch information
gustavolira authored Jan 23, 2025
1 parent fa0bf4e commit 5c96dd7
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 36 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/pr-build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
echo "Changes detected outside the e2e-tests or .ibm folders. Proceeding with the build."
echo "proceed_with_build=true" >> $GITHUB_ENV
else
echo "No changes outside the e2e-tests or .ibm folders. Skipping the build."
echo "No significant changes detected. Skipping the build."
echo "proceed_with_build=false" >> $GITHUB_ENV
fi
Expand All @@ -80,10 +80,11 @@ jobs:
IMAGE_TAG="pr-${{ github.event.number }}"
IMAGE_NAME="${{ env.REGISTRY }}/rhdh-community/rhdh:${IMAGE_TAG}"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://quay.io/rhdh-community/rhdh/manifests/${IMAGE_TAG}")
# Check if any image tag exists for the PR
IMAGE_TAGS=$(curl -s "https://quay.io/api/v1/repository/rhdh-community/rhdh/tag/" | jq -r --arg tag "$IMAGE_TAG" '.tags[] | select(.name | startswith($tag)) | .name')
if [ "$HTTP_CODE" -eq 200 ]; then
echo "Image $IMAGE_NAME already exists. Skipping the build."
if [ -n "$IMAGE_TAGS" ]; then
echo "Image $IMAGE_NAME or its variants already exist. Skipping the build."
echo "image_exists=true" >> $GITHUB_ENV
else
echo "Image $IMAGE_NAME does not exist. Proceeding with the build."
Expand Down
2 changes: 2 additions & 0 deletions .ibm/pipelines/env_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ GH_USER2_PASS=$(cat /tmp/secrets/GH_USER2_PASS)
GH_USER2_2FA_SECRET=$(cat /tmp/secrets/GH_USER2_2FA_SECRET)
GH_RHDH_QE_USER_TOKEN=$(cat /tmp/secrets/GH_RHDH_QE_USER_TOKEN)

K8S_CLUSTER_TOKEN_TEMPORARY=$(cat /tmp/secrets/K8S_CLUSTER_TOKEN_TEMPORARY)

GITLAB_TOKEN=$(cat /tmp/secrets/GITLAB_TOKEN)

RHDH_PR_OS_CLUSTER_URL=$(cat /tmp/secrets/RHDH_PR_OS_CLUSTER_URL)
Expand Down
4 changes: 2 additions & 2 deletions .ibm/pipelines/resources/postgres-db/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ spec:
pgbackrest:
resources:
limits:
cpu: 300m
requests:
cpu: 200m
requests:
cpu: 100m
pgbackrestConfig:
resources:
limits:
Expand Down
12 changes: 6 additions & 6 deletions .ibm/pipelines/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ spec:
EOD
}

# Monitors the status of an operator in an OpenShift namespace.
# It checks the ClusterServiceVersion (CSV) for a specific operator to verify if its phase matches an expected value.
# Monitors the status of an operator in an OpenShift namespace.
# It checks the ClusterServiceVersion (CSV) for a specific operator to verify if its phase matches an expected value.
check_operator_status() {
local timeout=${1:-300} # Timeout in seconds (default 300)
local namespace=$2 # Namespace to check
Expand All @@ -302,7 +302,7 @@ check_operator_status() {
echo "Expected status: ${expected_status}"

timeout "${timeout}" bash -c "
while true; do
while true; do
CURRENT_PHASE=\$(oc get csv -n '${namespace}' -o jsonpath='{.items[?(@.spec.displayName==\"${operator_name}\")].status.phase}')
echo \"Operator '${operator_name}' current phase: \${CURRENT_PHASE}\"
[[ \"\${CURRENT_PHASE}\" == \"${expected_status}\" ]] && echo \"Operator '${operator_name}' is now in '${expected_status}' phase.\" && break
Expand Down Expand Up @@ -627,7 +627,7 @@ install_acm_operator(){
wait_for_deployment "open-cluster-management" "multiclusterhub-operator"
oc apply -f "${DIR}/cluster/operators/acm/multiclusterhub.yaml"
# wait until multiclusterhub is Running.
timeout 600 bash -c 'while true; do
timeout 600 bash -c 'while true; do
CURRENT_PHASE=$(oc get multiclusterhub multiclusterhub -n open-cluster-management -o jsonpath="{.status.phase}")
echo "MulticlusterHub Current Status: $CURRENT_PHASE"
[[ "$CURRENT_PHASE" == "Running" ]] && echo "MulticlusterHub is now in Running phase." && break
Expand Down Expand Up @@ -705,7 +705,7 @@ initiate_deployments() {
configure_namespace "${NAME_SPACE_RBAC}"
configure_external_postgres_db "${NAME_SPACE_RBAC}"

# Initiate rbac instace deployment.
# Initiate rbac instance deployment.
local rbac_rhdh_base_url="https://${RELEASE_NAME_RBAC}-backstage-${NAME_SPACE_RBAC}.${K8S_CLUSTER_ROUTER_BASE}"
apply_yaml_files "${DIR}" "${NAME_SPACE_RBAC}" "${rbac_rhdh_base_url}"
echo "Deploying image from repository: ${QUAY_REPO}, TAG_NAME: ${TAG_NAME}, in NAME_SPACE: ${RELEASE_NAME_RBAC}"
Expand Down Expand Up @@ -769,7 +769,7 @@ force_delete_namespace() {
}

oc_login() {
oc login --token="${K8S_CLUSTER_TOKEN}" --server="${K8S_CLUSTER_URL}"
oc login --token="${K8S_CLUSTER_TOKEN}" --server="${K8S_CLUSTER_URL}" --insecure-skip-tls-verify=true
echo "OCP version: $(oc version)"
export K8S_CLUSTER_ROUTER_BASE=$(oc get route console -n openshift-console -o=jsonpath='{.spec.host}' | sed 's/^[^.]*\.//')
}
20 changes: 15 additions & 5 deletions e2e-tests/playwright/e2e/plugins/quay/quay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UIhelper } from "../../../utils/ui-helper";
import { Common } from "../../../utils/common";
import { ImageRegistry } from "../../../utils/quay/quay";

test.describe.skip("Test Quay.io plugin", () => {
test.describe("Test Quay.io plugin", () => {
const quayRepository = "rhdh-community/rhdh";
let uiHelper: UIhelper;

Expand All @@ -15,15 +15,25 @@ test.describe.skip("Test Quay.io plugin", () => {
await uiHelper.openSidebar("Catalog");
await uiHelper.selectMuiBox("Kind", "Component");
await uiHelper.clickByDataTestId("user-picker-all");
await uiHelper.clickLink("backstage-janus");
await uiHelper.clickLink("Backstage Showcase");
await uiHelper.clickTab("Image Registry");
});

test("Check if Image Registry is present", async () => {
test("Check if Image Registry is present", async ({ page }) => {
await uiHelper.verifyHeading(quayRepository);

const allGridColumnsText = ImageRegistry.getAllGridColumnsText();
await uiHelper.verifyColumnHeading(allGridColumnsText);
await uiHelper.verifyHeading(`Quay repository: ${quayRepository}`);

// Verify Headers
for (const column of allGridColumnsText) {
const columnLocator = page.locator("th").filter({ hasText: column });
await expect(columnLocator).toBeVisible();
}

await page
.locator('div[data-testid="quay-repo-table"]')
.waitFor({ state: "visible" });
// Verify cells with the adjusted selector
const allCellsIdentifier = ImageRegistry.getAllCellsIdentifier();
await uiHelper.verifyCellsInTable(allCellsIdentifier);
});
Expand Down
8 changes: 7 additions & 1 deletion e2e-tests/playwright/e2e/plugins/rbac/rbac.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import { RhdhAuthApiHack } from "../../../support/api/rhdh-auth-api-hack";
import RhdhRbacApi from "../../../support/api/rbac-api";
import { RbacConstants } from "../../../data/rbac-constants";
import { Policy } from "../../../support/api/rbac-api-structures";
import { CatalogImport } from "../../../support/pages/catalog-import";

/*
Note that:
The policies generated from a policy.csv or ConfigMap file cannot be edited or deleted using the Developer Hub Web UI.
The policies generated from a policy.csv or ConfigMap file cannot be edited or deleted using the Developer Hub Web UI.
https://docs.redhat.com/en/documentation/red_hat_developer_hub/1.3/html/authorization/managing-authorizations-by-using-the-web-ui#proc-rbac-ui-edit-role_title-authorization
*/
test.describe.serial("Test RBAC", () => {
Expand Down Expand Up @@ -454,6 +455,11 @@ test.describe.serial("Test RBAC", () => {
test("Test catalog-entity create is allowed", async () => {
await uiHelper.openSidebar("Create...");
expect(await uiHelper.isLinkVisible("Register Existing Component"));
await uiHelper.clickButton("Register Existing Component");
const catalogImport = new CatalogImport(page);
const component =
"https://github.com/janus-qe/custom-catalog-entities/blob/main/timestamp-catalog-info.yaml";
await catalogImport.registerExistingComponent(component);
});

test("Test bad PUT and PUT catalog-entity update policy", async () => {
Expand Down
27 changes: 9 additions & 18 deletions e2e-tests/playwright/utils/quay/quay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@ import { UI_HELPER_ELEMENTS } from "../../support/pageObjects/global-obj";

export class ImageRegistry {
static getAllCellsIdentifier() {
//create a regex to verify if the string contains pr on it

const tagText = /pr/i;
const lastModifiedDate = new RegExp(
/^[A-Za-z]{3} \d{1,2}, \d{4}, \d{1,2}:\d{2} (AM|PM)$/,
);
const size = /(GB|MB)/;
const tagText = /^pr-\d+(-[a-zA-Z0-9]+)?$/i; // Example: pr-123 or pr-123-abc
const lastModifiedDate =
/^[A-Za-z]{3} \d{1,2}, \d{4}, \d{1,2}:\d{2} (AM|PM)$/; // Example: Jan 21, 2025, 7:54 PM
const size = /^\d+(\.\d+)?\s?(GB|MB)$/; // Example: 1.16 GB or 512 MB
const expires =
"^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), \\d{1,2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4} \\d{1,2}:\\d{2}:\\d{2} [\\+\\-]\\d{4}$";
const expiresRegex = new RegExp(expires);
const manifest = /sha256/;
/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), \d{1,2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{1,2}:\d{2}:\d{2} [+-]\d{4}$/; // Example: Tue, 04 Feb 2025 22:54:18 -0000

return [
tagText,
lastModifiedDate,
this.securityScanRegex(),
size,
expiresRegex,
manifest,
];
const manifest = /^sha256/;
const securityScan =
/^(?:Critical:\s\d+,\s)?(?:High:\s\d+,\s)?(?:Medium:\s\d+,\s)?(?:Low:\s\d+,\s)?(?:Unknown:\s\d+)?$/i;
return [tagText, lastModifiedDate, securityScan, size, expires, manifest];
}

static getAllGridColumnsText() {
Expand Down

0 comments on commit 5c96dd7

Please sign in to comment.