|
| 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, setAppConfig } from '../support/nc-provisioning' |
| 9 | +import { createMailpitClient, waitForEmailTo, extractSignLink } from '../support/mailpit' |
| 10 | + |
| 11 | +test('request signatures from two signers in sequential order', async ({ page }) => { |
| 12 | + await login( |
| 13 | + page.request, |
| 14 | + process.env.NEXTCLOUD_ADMIN_USER ?? 'admin', |
| 15 | + process.env.NEXTCLOUD_ADMIN_PASSWORD ?? 'admin', |
| 16 | + ) |
| 17 | + |
| 18 | + await configureOpenSsl(page.request, 'LibreSign Test', { |
| 19 | + C: 'BR', |
| 20 | + OU: ['Organization Unit'], |
| 21 | + ST: 'Rio de Janeiro', |
| 22 | + O: 'LibreSign', |
| 23 | + L: 'Rio de Janeiro', |
| 24 | + }) |
| 25 | + |
| 26 | + await setAppConfig( |
| 27 | + page.request, |
| 28 | + 'libresign', |
| 29 | + 'identify_methods', |
| 30 | + JSON.stringify([ |
| 31 | + { name: 'account', enabled: false, mandatory: false }, |
| 32 | + { name: 'email', enabled: true, mandatory: true, signatureMethods: { clickToSign: { enabled: true } }, can_create_account: false }, |
| 33 | + ]), |
| 34 | + ) |
| 35 | + |
| 36 | + const mailpit = createMailpitClient() |
| 37 | + await mailpit.deleteMessages() |
| 38 | + |
| 39 | + await page.goto('./apps/libresign') |
| 40 | + await page.getByRole('button', { name: 'Upload from URL' }).click() |
| 41 | + 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') |
| 42 | + await page.getByRole('button', { name: 'Send' }).click() |
| 43 | + |
| 44 | + // Add first signer — only email method is active, so the field appears directly (no tabs) |
| 45 | + await page.getByRole('button', { name: 'Add signer' }).click() |
| 46 | + await page.getByPlaceholder('Email').click() |
| 47 | + await page.getByPlaceholder('Email').pressSequentially('signer01@libresign.coop', { delay: 50 }) |
| 48 | + await page.getByRole('option', { name: 'signer01@libresign.coop' }).click() |
| 49 | + await page.getByRole('textbox', { name: 'Signer name' }).fill('Signer 01') |
| 50 | + await page.getByRole('button', { name: 'Save' }).click() |
| 51 | + |
| 52 | + // Add second signer |
| 53 | + await page.getByRole('button', { name: 'Add signer' }).click() |
| 54 | + await page.getByPlaceholder('Email').click() |
| 55 | + await page.getByPlaceholder('Email').pressSequentially('signer02@libresign.coop', { delay: 50 }) |
| 56 | + await page.getByRole('option', { name: 'signer02@libresign.coop' }).click() |
| 57 | + await page.getByRole('textbox', { name: 'Signer name' }).fill('Signer 02') |
| 58 | + await page.getByRole('button', { name: 'Save' }).click() |
| 59 | + |
| 60 | + // Enable sequential signing. |
| 61 | + // The checkbox input is hidden by CSS; click the visible label text to toggle it. |
| 62 | + await expect(page.getByLabel('Sign in order')).toBeVisible() |
| 63 | + await page.getByText('Sign in order').click() |
| 64 | + await expect(page.getByLabel('Sign in order')).toBeChecked() |
| 65 | + |
| 66 | + // Send the signature request |
| 67 | + await page.getByRole('button', { name: 'Request signatures' }).click() |
| 68 | + await page.getByRole('button', { name: 'Send' }).click() |
| 69 | + |
| 70 | + // In sequential mode only signer01 (order 1) gets the email immediately. |
| 71 | + // Proof: signer01's email arrives, but signer02's does NOT at this point. |
| 72 | + const email01 = await waitForEmailTo(mailpit, 'signer01@libresign.coop', 'LibreSign: There is a file for you to sign') |
| 73 | + |
| 74 | + const afterFirst = await mailpit.searchMessages({ query: 'subject:"LibreSign: There is a file for you to sign"' }) |
| 75 | + expect(afterFirst.messages).toHaveLength(1) |
| 76 | + |
| 77 | + // Logout before signing as signer01 — the sign link is for an email-based signer |
| 78 | + // (no Nextcloud account), so it must be accessed without an active admin session. |
| 79 | + await page.getByRole('button', { name: 'Settings menu' }).click() |
| 80 | + await page.getByRole('link', { name: 'Log out' }).click() |
| 81 | + |
| 82 | + // Signer01 signs via the link received in the email |
| 83 | + const signLink = extractSignLink(email01.Text) |
| 84 | + if (!signLink) throw new Error('Sign link not found in email') |
| 85 | + await page.goto(signLink) |
| 86 | + await page.getByRole('button', { name: 'Sign the document.' }).click() |
| 87 | + await page.getByRole('button', { name: 'Sign document' }).click() |
| 88 | + await page.waitForURL('**/validation/**') |
| 89 | + await expect(page.getByText('This document is valid')).toBeVisible() |
| 90 | + // Signer01 signed; signer02 is still waiting (sequential mode proof at this point) |
| 91 | + await expect(page.getByText('Signer 01')).toBeVisible() |
| 92 | + await page.getByRole('button', { name: 'Expand details of Signer 01' }).click() |
| 93 | + await page.getByRole('button', { name: 'Expand validation status', exact: true }).click(); |
| 94 | + await page.getByRole('link', { name: 'Document integrity verified' }).click(); |
| 95 | + await page.getByRole('button', { name: 'Expand document certification', exact: true }).click(); |
| 96 | + await page.getByRole('link', { name: 'Document has not been' }).click(); |
| 97 | + |
| 98 | + await expect(page.getByText('Signer 02')).toBeVisible() |
| 99 | + await expect(page.getByText('Not signed yet')).toBeVisible() |
| 100 | + |
| 101 | + // Now that signer01 has signed, signer02 must receive their notification. |
| 102 | + await waitForEmailTo(mailpit, 'signer02@libresign.coop', 'LibreSign: There is a file for you to sign') |
| 103 | + |
| 104 | + const afterSecond = await mailpit.searchMessages({ query: 'subject:"LibreSign: There is a file for you to sign"' }) |
| 105 | + expect(afterSecond.messages).toHaveLength(2) |
| 106 | +}) |
0 commit comments