|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { expect, test } from '@playwright/test' |
| 7 | +import { login } from '../support/nc-login' |
| 8 | +import { configureOpenSsl, deleteUserPfx, setAppConfig } from '../support/nc-provisioning' |
| 9 | + |
| 10 | +async function prepareSignFlow(page: Parameters<typeof test>[1] extends (args: infer T) => any ? T['page'] : never, adminUser: string) { |
| 11 | + await page.goto('./apps/libresign') |
| 12 | + |
| 13 | + await page.getByRole('button', { name: 'Upload from URL' }).click() |
| 14 | + await page.getByRole('textbox', { name: 'URL of a PDF file' }).fill('https://raw.githubusercontent.com/LibreSign/libresign/main/tests/php/fixtures/pdfs/small_valid.pdf') |
| 15 | + await page.getByRole('button', { name: 'Send' }).click() |
| 16 | + await page.getByRole('button', { name: 'Add signer' }).click() |
| 17 | + await page.getByPlaceholder('Account').fill(adminUser) |
| 18 | + await page.getByText('admin@email.tld').click() |
| 19 | + await page.getByRole('button', { name: 'Save' }).click() |
| 20 | + await page.getByRole('button', { name: 'Request signatures' }).click() |
| 21 | + await page.getByRole('button', { name: 'Send' }).click() |
| 22 | + await page.getByRole('button', { name: 'Sign document' }).click() |
| 23 | + await page.getByRole('button', { name: 'Define a password and sign the document.' }).click() |
| 24 | + await page.getByLabel('Enter a password').fill('Password1234') |
| 25 | + await page.getByRole('button', { name: 'Confirm' }).click() |
| 26 | + await page.getByRole('button', { name: 'Sign the document.' }).click() |
| 27 | + await page.getByLabel('Signature password').fill('Password1234') |
| 28 | +} |
| 29 | + |
| 30 | +async function bootstrapAdminCertificate(page: Parameters<typeof test>[1] extends (args: infer T) => any ? T['page'] : never) { |
| 31 | + const adminUser = process.env.NEXTCLOUD_ADMIN_USER ?? 'admin' |
| 32 | + const adminPassword = process.env.NEXTCLOUD_ADMIN_PASSWORD ?? 'admin' |
| 33 | + |
| 34 | + await login(page.request, adminUser, adminPassword) |
| 35 | + |
| 36 | + await configureOpenSsl(page.request, 'LibreSign Test', { |
| 37 | + C: 'BR', |
| 38 | + OU: ['Organization Unit'], |
| 39 | + ST: 'Rio de Janeiro', |
| 40 | + O: 'LibreSign', |
| 41 | + L: 'Rio de Janeiro', |
| 42 | + }) |
| 43 | + |
| 44 | + await setAppConfig( |
| 45 | + page.request, |
| 46 | + 'libresign', |
| 47 | + 'identify_methods', |
| 48 | + JSON.stringify([ |
| 49 | + { name: 'account', enabled: true, mandatory: true, signatureMethods: { password: { enabled: true } } }, |
| 50 | + { name: 'email', enabled: false, mandatory: false }, |
| 51 | + ]), |
| 52 | + ) |
| 53 | + |
| 54 | + await setAppConfig( |
| 55 | + page.request, |
| 56 | + 'libresign', |
| 57 | + 'crl_external_validation_enabled', |
| 58 | + '1', |
| 59 | + ) |
| 60 | + |
| 61 | + await deleteUserPfx(page.request, adminUser, adminPassword) |
| 62 | + |
| 63 | + return { adminUser } |
| 64 | +} |
| 65 | + |
| 66 | +test('switches from blocked (enabled) to normal (disabled) without extra scenarios', async ({ page }) => { |
| 67 | + const { adminUser } = await bootstrapAdminCertificate(page) |
| 68 | + await prepareSignFlow(page, adminUser) |
| 69 | + |
| 70 | + const signRoute = '**/ocs/v2.php/apps/libresign/api/v1/sign/**' |
| 71 | + |
| 72 | + const blockedHandler = async (route) => { |
| 73 | + await route.fulfill({ |
| 74 | + status: 422, |
| 75 | + contentType: 'application/json', |
| 76 | + body: JSON.stringify({ |
| 77 | + ocs: { |
| 78 | + meta: { |
| 79 | + status: 'failure', |
| 80 | + statuscode: 422, |
| 81 | + message: 'Certificate revocation status could not be verified', |
| 82 | + }, |
| 83 | + data: { |
| 84 | + action: 0, |
| 85 | + errors: [{ |
| 86 | + code: 422, |
| 87 | + message: 'Certificate revocation status could not be verified', |
| 88 | + }], |
| 89 | + }, |
| 90 | + }, |
| 91 | + }), |
| 92 | + }) |
| 93 | + } |
| 94 | + |
| 95 | + await page.route(signRoute, blockedHandler) |
| 96 | + |
| 97 | + await page.getByRole('button', { name: 'Sign document' }).click() |
| 98 | + |
| 99 | + await expect(page.getByLabel('Signature password')).toBeHidden() |
| 100 | + await expect(page.getByRole('button', { name: 'Sign the document.' })).toBeHidden() |
| 101 | + await expect(page.getByRole('button', { name: 'Try signing again' })).toBeVisible() |
| 102 | + await expect(page.locator('.button-wrapper').getByText('Certificate revocation status could not be verified').first()).toBeVisible() |
| 103 | + await page.screenshot({ path: '/tmp/playwright-results/non-retriable-blocked-ui.png', fullPage: true }) |
| 104 | + |
| 105 | + await setAppConfig( |
| 106 | + page.request, |
| 107 | + 'libresign', |
| 108 | + 'crl_external_validation_enabled', |
| 109 | + '0', |
| 110 | + ) |
| 111 | + |
| 112 | + await page.unroute(signRoute, blockedHandler) |
| 113 | + |
| 114 | + await page.route(signRoute, async (route) => { |
| 115 | + await route.fulfill({ |
| 116 | + status: 200, |
| 117 | + contentType: 'application/json', |
| 118 | + body: JSON.stringify({ |
| 119 | + ocs: { |
| 120 | + meta: { |
| 121 | + status: 'ok', |
| 122 | + statuscode: 200, |
| 123 | + message: null, |
| 124 | + }, |
| 125 | + data: { |
| 126 | + action: 0, |
| 127 | + status: 'signed', |
| 128 | + }, |
| 129 | + }, |
| 130 | + }), |
| 131 | + }) |
| 132 | + }) |
| 133 | + |
| 134 | + await page.getByRole('button', { name: 'Try signing again' }).click() |
| 135 | + await page.getByRole('button', { name: 'Sign the document.' }).click() |
| 136 | + await page.getByLabel('Signature password').fill('Password1234') |
| 137 | + await page.getByRole('button', { name: 'Sign document' }).click() |
| 138 | + |
| 139 | + await expect(page.getByText('Signing is blocked until the certificate validation issue is resolved.')).toBeHidden() |
| 140 | + await expect(page.getByRole('button', { name: 'Try signing again' })).toBeHidden() |
| 141 | + await page.screenshot({ path: '/tmp/playwright-results/non-retriable-normal-ui.png', fullPage: true }) |
| 142 | +}) |
0 commit comments