chore: Add Vault Mode CI setup for E2E tests (#12577)

* feat: vault mode access control and mfa on vault entry

* chore: vault mode ci setup for e2e tests

chore: vault mode ci setup

* test: restore web packages changes

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>

* test: remove keycloak certs

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>

* test: set keycloak server envs

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>

* test: adding csp file

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>

* test: adding keycloak config

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>

* test: adding scope with email acr

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>

* test: exclude vault storage from parallel e2e tests

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>

* test: remove debugging codes

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>

* test: handle vault mode in keycloak group setup

* test: revert some configs

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>

* test: updating the vault pageObject layout

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>

* fix: reusing otp authentication of mfa

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>

* fix: update userAuthenticatesWithOTP function

* fix: use a new OIDC authorization-code login for OCIS token

---------

Signed-off-by: Kavita Gautam <kavita@jankaritech.com>
This commit is contained in:
Kavita gautam authored and GitHub committed 2026-08-20 16:26:01 +05:45
1 parent de6d5452c7
commit c828e41cba
13 files changed
+265 -17

No files matched your search

+12 -8
View File
@@ -449,13 +449,13 @@ jobs:
matrix:
include:
- suite: part-1
args: "--type playwright --total-parts 4 --xsuites search,app-provider,ocm,keycloak,mfa,oidc --run-part 1"
args: "--type playwright --total-parts 4 --xsuites search,app-provider,ocm,keycloak,mfa,oidc,vault-storage --run-part 1"
- suite: part-2
args: "--type playwright --total-parts 4 --xsuites search,app-provider,ocm,keycloak,mfa,oidc --run-part 2"
args: "--type playwright --total-parts 4 --xsuites search,app-provider,ocm,keycloak,mfa,oidc,vault-storage --run-part 2"
- suite: part-3
args: "--type playwright --total-parts 4 --xsuites search,app-provider,ocm,keycloak,mfa,oidc --run-part 3"
args: "--type playwright --total-parts 4 --xsuites search,app-provider,ocm,keycloak,mfa,oidc,vault-storage --run-part 3"
- suite: part-4
args: "--type playwright --total-parts 4 --xsuites search,app-provider,ocm,keycloak,mfa,oidc --run-part 4"
args: "--type playwright --total-parts 4 --xsuites search,app-provider,ocm,keycloak,mfa,oidc,vault-storage --run-part 4"
- suite: search
args: "--type playwright --suites search"
tika: true
@@ -477,6 +477,9 @@ jobs:
- suite: ocm
args: "--type playwright --suites ocm"
federated: true
- suite: vault-storage
args: "--type playwright --suites vault-storage"
vault_storage: true
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
@@ -519,7 +522,7 @@ jobs:
# --- Keycloak (keycloak and mfa suites) ---
- name: Generate Keycloak certs
if: matrix.keycloak == true || matrix.mfa == true
if: matrix.keycloak == true || matrix.mfa == true || matrix.vault_storage == true
run: |
mkdir -p keycloak-certs
openssl req -x509 -newkey rsa:2048 \
@@ -530,7 +533,7 @@ jobs:
chmod -R 777 keycloak-certs
- name: Start Postgres
if: matrix.keycloak == true || matrix.mfa == true
if: matrix.keycloak == true || matrix.mfa == true || matrix.vault_storage == true
run: |
docker run -d --name postgres --network host \
-e POSTGRES_DB=keycloak \
@@ -540,12 +543,12 @@ jobs:
timeout 30 bash -c 'until docker exec postgres pg_isready -U keycloak; do sleep 1; done'
- name: Start Keycloak
if: matrix.keycloak == true || matrix.mfa == true
if: matrix.keycloak == true || matrix.mfa == true || matrix.vault_storage == true
run: |
# The mfa suite needs a different realm with TOTP MFA configured.
# ocis-ci-realm uses ocis-server:9200, ocis-mfa-ci-realm uses localhost:9200;
# ocis runs on 127.0.0.1:9200 so we rewrite both forms.
if [[ "${{ matrix.mfa }}" == "true" ]]; then
if [[ "${{ matrix.mfa }}" == "true" || "${{ matrix.vault_storage }}" == "true" ]]; then
REALM_FILE=tests/config/ci/ocis-mfa-ci-realm.dist.json
else
REALM_FILE=tests/config/ci/ocis-ci-realm.dist.json
@@ -624,6 +627,7 @@ jobs:
OIDC_IFRAME_NEEDED: ${{ matrix.oidc_iframe == true && 'true' || 'false' }}
COLLABORATION_NEEDED: ${{ matrix.collaboration == true && 'true' || 'false' }}
FEDERATED_NEEDED: ${{ matrix.federated == true && 'true' || 'false' }}
VAULT_STORAGE_NEEDED: ${{ matrix.vault_storage == true && 'true' || 'false' }}
- name: Upload tracing result
if: failure()
+48 -2
View File
@@ -127,8 +127,9 @@ def main() -> int:
oidc_iframe_needed = os.environ.get("OIDC_IFRAME_NEEDED", "").lower() == "true"
collaboration_needed = os.environ.get("COLLABORATION_NEEDED", "").lower() == "true"
federated_needed = os.environ.get("FEDERATED_NEEDED", "").lower() == "true"
vault_storage_needed = os.environ.get("VAULT_STORAGE_NEEDED", "").lower() == "true"
# MFA mode runs ocis behind keycloak with TOTP enforced
keycloak_needed = keycloak_needed or mfa_needed
keycloak_needed = keycloak_needed or mfa_needed or vault_storage_needed
repo_root = Path(__file__).resolve().parents[2]
ocis_bin = repo_root / "ocis/bin/ocis"
@@ -219,7 +220,7 @@ def main() -> int:
# - mfa flow needs `acr` so Keycloak emits the LoA claim used for step-up.
if oidc_needed:
gha_web_cfg["openIdConnect"]["scope"] = "openid profile email offline_access"
if mfa_needed:
if mfa_needed or vault_storage_needed:
gha_web_cfg["openIdConnect"]["scope"] = "openid profile email acr"
gha_web_cfg_path = ocis_config_dir / "web-ui-config.json"
@@ -332,6 +333,14 @@ def main() -> int:
"WEB_OIDC_SCOPE": "openid profile email acr",
})
if vault_storage_needed:
server_env.update({
"OCIS_ENABLE_VAULT_MODE": "true",
"FRONTEND_ENABLE_VAULT_MODE": "true",
"OCIS_MFA_ENABLED": "true",
"WEB_OIDC_SCOPE": "openid profile email acr",
})
# The two oidc tests need a short access-token lifetime so token renewal
# actually triggers within the test window. refreshToken.spec.ts uses a
# refresh token (offline_access scope); iframeTokenRenewal.spec.ts uses
@@ -531,6 +540,43 @@ def main() -> int:
if mfa_needed:
playwright_env["MFA"] = "true"
if vault_storage_needed:
vault_data_dir = Path.home() / "ocis/storage/users-vault"
vault_data_dir.mkdir(parents=True, exist_ok=True)
playwright_env["VAULT_MODE"] = "true"
vault_env = {
**server_env,
"STORAGE_USERS_ENABLE_VAULT_MODE": "true",
"STORAGE_USERS_SERVICE_NAME": "storage-users-vault",
"STORAGE_USERS_GRPC_ADDR": "127.0.0.1:19285",
"STORAGE_USERS_HTTP_ADDR": "127.0.0.1:19286",
"STORAGE_USERS_DATA_SERVER_URL": "http://127.0.0.1:19286/data",
"STORAGE_USERS_DEBUG_ADDR": "127.0.0.1:19287",
"STORAGE_USERS_OCIS_ROOT": str(vault_data_dir),
"STORAGE_USERS_EVENTS_CONSUMER_GROUP": "vault-dcfs",
"PROXY_CSP_CONFIG_FILE_LOCATION": str(repo_root / "tests/config/ci/csp.yaml")
}
print("Starting storage-users-vault...")
vault_proc = subprocess.Popen(
[str(ocis_bin), "storage-users", "server"],
env=vault_env,
)
procs.append(vault_proc)
wait_for(
lambda: subprocess.run(
["curl", "-sf", "http://127.0.0.1:19287/healthz"],
capture_output=True,
).returncode == 0,
120,
"storage-users-vault",
)
print("vault ready.")
if federated_needed:
playwright_env["FEDERATED_BASE_URL_OCIS"] = "localhost:10200"
trusted_certs.append(federated_cert)
+2 -1
View File
@@ -59,5 +59,6 @@ export const config = {
reportTracing: process.env.REPORT_TRACING === 'true',
failOnUncaughtConsoleError: process.env.FAIL_ON_UNCAUGHT_CONSOLE_ERR === 'true',
skipA11y: process.env.SKIP_A11Y_TESTS === 'false',
mfa: process.env.MFA === 'true'
mfa: process.env.MFA === 'true',
vaultMode: process.env.VAULT_MODE === 'true'
}
+6 -2
View File
@@ -31,7 +31,9 @@ export const test = base.extend<{
if (!config.predefinedUsers && !config.mfa && adminUser) {
if (config.keycloak) {
await api.keycloak.refreshAccessTokenForKeycloakUser(adminUser)
await api.keycloak.refreshAccessTokenForKeycloakOcisUser(adminUser)
// use a new OIDC authorization-code login for the OCIS token instead of refreshing the shared Admin refresh token.
// This avoids Keycloak refresh-token rotation races between workers
await api.keycloak.setAccessTokenForKeycloakOcisUser(adminUser)
} else {
await api.token.refreshAccessToken(adminUser)
}
@@ -65,7 +67,9 @@ export const test = base.extend<{
const user = world.usersEnvironment.getUser({ key: config.keycloakAdminUser })
await api.keycloak.setAccessTokenForKeycloakOcisUser(user)
await api.keycloak.setAccessTokenForKeycloakUser(user)
await storeKeycloakGroups(user)
if (!config.vaultMode) {
await storeKeycloakGroups(user)
}
} else {
const user = world.usersEnvironment.getUser({ key: config.adminUsername })
await api.token.setAccessAndRefreshToken(user)
@@ -0,0 +1,41 @@
import { test } from '../../environment/test'
import * as api from '../../steps/api/api'
import * as ui from '../../steps/ui/index'
test.describe('Vault Mode', { tag: '@predefined-users' }, () => {
test.beforeEach(async () => {
await api.usersHaveBeenCreated({
stepUser: 'Admin',
users: ['Alice']
})
await ui.userLogsIn({ stepUser: 'Alice' })
})
test('User with vault permission can access Vault mode with second factor authentication', async () => {
await ui.userIsInDriveMode({
stepUser: 'Alice'
})
await ui.userSwitchesToVaultMode({
stepUser: 'Alice'
})
await ui.userIsRedirectedToAuthenticatorPage({
stepUser: 'Alice'
})
await ui.userAuthenticatesWithOTP({ stepUser: 'Alice', deviceName: 'test' })
await ui.userIsInVaultMode({
stepUser: 'Alice'
})
await ui.userSwitchesToDriveMode({
stepUser: 'Alice'
})
await ui.userIsInDriveMode({
stepUser: 'Alice'
})
})
})
+1
View File
@@ -12,3 +12,4 @@ export * from './navigateByUrl'
export * from './search'
export * from './links'
export * from './federation'
export * from './vault'
+1 -1
View File
@@ -72,7 +72,7 @@ export async function logInWithOTP({ stepUser }: { stepUser: string }): Promise<
const sessionObject = await createNewSession(stepUser)
const { page } = world.actorsEnvironment.getActor({ key: stepUser })
const image = await Jimp.read('./qr.png')
const image = await Jimp.read(test.info().outputPath('qr.png'))
const { data, width, height } = image.bitmap
const errorLocator = page.locator('#input-error-otp')
for (let attempt = 0; attempt < 2; attempt++) {
+63
View File
@@ -0,0 +1,63 @@
import { expect } from '@playwright/test'
import { getWorld } from '../../environment/world'
import { config } from '../../config'
import { VaultActions, VaultPage } from '../../support/objects/vault'
/**
* Switch user from Drive → Vault mode
*/
export async function userSwitchesToVaultMode({ stepUser }: { stepUser: string }): Promise<void> {
const world = getWorld()
const { page } = world.actorsEnvironment.getActor({ key: stepUser })
const vaultActions = new VaultActions({ page })
await vaultActions.userEntersVaultMode()
}
/**
* Assert user is redirected to the MFA authenticator page
*/
export async function userIsRedirectedToAuthenticatorPage({
stepUser
}: {
stepUser: string
}): Promise<void> {
const world = getWorld()
const { page } = world.actorsEnvironment.getActor({ key: stepUser })
const vaultPage = new VaultPage({ page })
await expect(page).toHaveURL((url) => url.href.startsWith(config.keycloakUrl))
await expect(vaultPage.authenticatorHeading).toBeVisible()
}
/**
* Assert user is in Vault mode
*/
export async function userIsInVaultMode({ stepUser }: { stepUser: string }): Promise<void> {
const world = getWorld()
const { page } = world.actorsEnvironment.getActor({ key: stepUser })
const vaultPage = new VaultPage({ page })
const vaultPageUrl = `${config.baseUrl}/vault`
await expect(page).toHaveURL((url) => url.href.startsWith(vaultPageUrl))
await expect(vaultPage.vaultBreadcrumb).toBeVisible()
}
/**
* Switch user from Vault → Drive mode
*/
export async function userSwitchesToDriveMode({ stepUser }: { stepUser: string }): Promise<void> {
const world = getWorld()
const { page } = world.actorsEnvironment.getActor({ key: stepUser })
const vaultActions = new VaultActions({ page })
await vaultActions.userEntersDriveMode()
}
/**
* Assert user is in Drive mode
*/
export async function userIsInDriveMode({ stepUser }: { stepUser: string }): Promise<void> {
const world = getWorld()
const { page } = world.actorsEnvironment.getActor({ key: stepUser })
const vaultPage = new VaultPage({ page })
const drivePageUrl = `${config.baseUrl}/files`
await expect(page).toHaveURL((url) => url.href.startsWith(drivePageUrl))
await expect(vaultPage.driveBreadcrumb).toBeVisible()
}
@@ -1,5 +1,5 @@
import { basename } from 'path'
import { Page, expect } from '@playwright/test'
import { Page, expect, test } from '@playwright/test'
import { objects } from '../../../index'
import { getOtpFromImage } from '../../../utils/mfa'
import { Jimp } from 'jimp'
@@ -68,8 +68,9 @@ export const resetLogo = async (page: Page): Promise<void> => {
export const userAuthenticatesWithOTP = async (page: Page, deviceName: string): Promise<void> => {
const element = page.locator('#kc-totp-secret-qr-code')
await element.screenshot({ path: 'qr.png' })
const image = await Jimp.read('./qr.png')
const qrCodePath = test.info().outputPath('qr.png')
await element.screenshot({ path: qrCodePath })
const image = await Jimp.read(qrCodePath)
const { data, width, height } = image.bitmap
const otp = await getOtpFromImage(data, width, height)
await page.locator('#totp').fill(String(otp))
+1
View File
@@ -6,3 +6,4 @@ export * as urlNavigation from './url-navigation'
export * as appStore from './app-store'
export * as scienceMesh from './federation'
export * as a11y from './a11y'
export * as vault from './vault'
@@ -0,0 +1,32 @@
import { Page } from '@playwright/test'
import { VaultPage } from './page/VaultPage'
import { config } from '../../../config'
export interface userAuthenticatesWithOTPArgs {
page: Page
otp: string
}
export const userEntersVaultMode = async ({ page }: { page: Page }): Promise<void> => {
const vaultPage = new VaultPage({ page })
await vaultPage.driveOption.click()
await vaultPage.vaultOption.click()
await vaultPage.qrImage.waitFor({ state: 'visible' })
}
export const waitForVaultMode = async ({ page }: { page: Page }): Promise<void> => {
const vaultPage = new VaultPage({ page })
const vaultUrl = `${config.baseUrl}/vault`
await page.waitForURL((url) => url.href.startsWith(vaultUrl))
await vaultPage.vaultBreadcrumb.waitFor()
}
export const userEntersDriveMode = async ({ page }: { page: Page }): Promise<void> => {
const vaultPage = new VaultPage({ page })
await vaultPage.vaultOption.click()
await vaultPage.driveOption.click()
await vaultPage.driveBreadcrumb.waitFor({ state: 'visible' })
}
@@ -0,0 +1,25 @@
import { Page } from '@playwright/test'
import * as po from './actions'
import { VaultPage } from './page/VaultPage'
export { VaultPage }
export class VaultActions {
#page: Page
constructor({ page }: { page: Page }) {
this.#page = page
}
async userEntersVaultMode(): Promise<void> {
await po.userEntersVaultMode({ page: this.#page })
}
async waitForVaultMode(): Promise<void> {
await po.waitForVaultMode({ page: this.#page })
}
async userEntersDriveMode(): Promise<void> {
await po.userEntersDriveMode({ page: this.#page })
}
}
@@ -0,0 +1,29 @@
import { Locator, Page } from '@playwright/test'
export class VaultPage {
private readonly page: Page
public readonly driveOption: Locator
public readonly vaultOption: Locator
public readonly authenticatorHeading: Locator
public readonly qrImage: Locator
public readonly oneTimeCodeTextbox: Locator
public readonly otpSubmitButton: Locator
public readonly driveBreadcrumb: Locator
public readonly vaultBreadcrumb: Locator
public constructor({ page }: { page: Page }) {
this.page = page
this.driveOption = page.getByRole('button', { name: 'DRIVE' })
this.vaultOption = page.getByRole('button', { name: 'VAULT' })
this.authenticatorHeading = page.getByRole('heading', {
name: 'Mobile Authenticator Setup'
})
this.qrImage = page.locator('#kc-totp-secret-qr-code')
this.oneTimeCodeTextbox = page.locator('#totp')
this.otpSubmitButton = page.getByRole('button', { name: 'Submit' })
this.driveBreadcrumb = page.getByRole('link', { name: 'Drive' })
this.vaultBreadcrumb = page.getByRole('link', { name: 'Vault' })
}
}