|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { test, expect } from '@playwright/test' |
| 7 | +import type { APIRequestContext, APIResponse } from '@playwright/test' |
| 8 | +import { login } from '../support/nc-login' |
| 9 | +import { configureOpenSsl, deleteAppConfig, setAppConfig } from '../support/nc-provisioning' |
| 10 | + |
| 11 | +type OcsResponse<T> = { |
| 12 | + ocs: { |
| 13 | + data: T |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +type CreatedRequest = { |
| 18 | + uuid?: string |
| 19 | +} |
| 20 | + |
| 21 | +async function requestLibreSignAsAdmin( |
| 22 | + request: APIRequestContext, |
| 23 | + path: string, |
| 24 | + body: Record<string, unknown>, |
| 25 | +): Promise<APIResponse> { |
| 26 | + const adminUser = process.env.NEXTCLOUD_ADMIN_USER ?? 'admin' |
| 27 | + const adminPassword = process.env.NEXTCLOUD_ADMIN_PASSWORD ?? 'admin' |
| 28 | + const auth = 'Basic ' + Buffer.from(`${adminUser}:${adminPassword}`).toString('base64') |
| 29 | + |
| 30 | + return request.fetch(`./ocs/v2.php/apps/libresign/api/v1${path}`, { |
| 31 | + method: 'POST', |
| 32 | + headers: { |
| 33 | + 'OCS-ApiRequest': 'true', |
| 34 | + Accept: 'application/json', |
| 35 | + Authorization: auth, |
| 36 | + 'Content-Type': 'application/json', |
| 37 | + }, |
| 38 | + data: JSON.stringify(body), |
| 39 | + failOnStatusCode: false, |
| 40 | + }) |
| 41 | +} |
| 42 | + |
| 43 | +test('validation page accepts signer with nullable email payload', async ({ page }) => { |
| 44 | + await login( |
| 45 | + page.request, |
| 46 | + process.env.NEXTCLOUD_ADMIN_USER ?? 'admin', |
| 47 | + process.env.NEXTCLOUD_ADMIN_PASSWORD ?? 'admin', |
| 48 | + ) |
| 49 | + |
| 50 | + await configureOpenSsl(page.request, 'LibreSign Test', { |
| 51 | + C: 'BR', |
| 52 | + OU: ['Organization Unit'], |
| 53 | + ST: 'Rio de Janeiro', |
| 54 | + O: 'LibreSign', |
| 55 | + L: 'Rio de Janeiro', |
| 56 | + }) |
| 57 | + |
| 58 | + await setAppConfig( |
| 59 | + page.request, |
| 60 | + 'libresign', |
| 61 | + 'identify_methods', |
| 62 | + JSON.stringify([ |
| 63 | + { name: 'account', enabled: false, mandatory: false }, |
| 64 | + { name: 'email', enabled: true, mandatory: true, signatureMethods: { emailToken: { enabled: true } }, can_create_account: false }, |
| 65 | + ]), |
| 66 | + ) |
| 67 | + await setAppConfig(page.request, 'libresign', 'signature_engine', 'PhpNative') |
| 68 | + await deleteAppConfig(page.request, 'libresign', 'tsa_url') |
| 69 | + |
| 70 | + const pdfResponse = await page.request.get('https://raw.githubusercontent.com/LibreSign/libresign/main/tests/php/fixtures/pdfs/small_valid.pdf', { |
| 71 | + failOnStatusCode: true, |
| 72 | + }) |
| 73 | + const pdfBase64 = Buffer.from(await pdfResponse.body()).toString('base64') |
| 74 | + |
| 75 | + const createResponse = await requestLibreSignAsAdmin(page.request, '/request-signature', { |
| 76 | + name: `Validation nullable email ${Date.now()}`, |
| 77 | + file: { |
| 78 | + name: 'nullable-email.pdf', |
| 79 | + base64: pdfBase64, |
| 80 | + }, |
| 81 | + signers: [{ |
| 82 | + displayName: 'Signer Nullable Email', |
| 83 | + notify: 0, |
| 84 | + identifyMethods: [{ |
| 85 | + method: 'email', |
| 86 | + value: 'signer01@libresign.coop', |
| 87 | + mandatory: 1, |
| 88 | + }], |
| 89 | + }], |
| 90 | + }) |
| 91 | + |
| 92 | + expect(createResponse.ok()).toBeTruthy() |
| 93 | + const createdData = await createResponse.json() as OcsResponse<CreatedRequest> |
| 94 | + const fileUuid = createdData.ocs.data.uuid |
| 95 | + expect(fileUuid).toBeTruthy() |
| 96 | + |
| 97 | + await page.route('**/ocs/v2.php/apps/libresign/api/v1/file/validate/uuid/**', async (route) => { |
| 98 | + const originalResponse = await route.fetch() |
| 99 | + const payload = await originalResponse.json() as Record<string, unknown> |
| 100 | + const ocs = payload.ocs as Record<string, unknown> | undefined |
| 101 | + const data = ocs?.data as Record<string, unknown> | undefined |
| 102 | + |
| 103 | + if (data && Array.isArray(data.signers) && data.signers.length > 0) { |
| 104 | + const firstSigner = data.signers[0] as Record<string, unknown> |
| 105 | + firstSigner.email = null |
| 106 | + } |
| 107 | + |
| 108 | + await route.fulfill({ |
| 109 | + status: originalResponse.status(), |
| 110 | + headers: { |
| 111 | + ...originalResponse.headers(), |
| 112 | + 'content-type': 'application/json', |
| 113 | + }, |
| 114 | + body: JSON.stringify(payload), |
| 115 | + }) |
| 116 | + }) |
| 117 | + |
| 118 | + await page.goto(`./apps/libresign/p/validation/${fileUuid}`) |
| 119 | + |
| 120 | + await expect(page.getByText('This document is valid')).toBeVisible() |
| 121 | + await expect(page.getByText('Failed to validate document')).not.toBeVisible() |
| 122 | +}) |
0 commit comments