|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { windowsPackageInvocation, windowsSigningArgs } from '../scripts/package-win' |
| 3 | + |
| 4 | +const signingEnvironment: NodeJS.ProcessEnv = { |
| 5 | + AZURE_TENANT_ID: 'tenant-id', |
| 6 | + AZURE_CLIENT_ID: 'client-id', |
| 7 | + AZURE_CLIENT_SECRET: 'client-secret', |
| 8 | + AZURE_SIGNING_ENDPOINT: 'https://example.test', |
| 9 | + AZURE_SIGNING_ACCOUNT: 'signing-account', |
| 10 | + AZURE_SIGNING_CERT_PROFILE: 'certificate-profile', |
| 11 | + AZURE_SIGNING_PUBLISHER_NAME: 'CN=Example Publisher, O=Example Publisher, L=Redmond, S=WA, C=US', |
| 12 | +} |
| 13 | + |
| 14 | +describe('Windows Azure signing configuration', () => { |
| 15 | + it('leaves the build unsigned when no signing variables are set', () => { |
| 16 | + expect(windowsSigningArgs({})).toEqual([]) |
| 17 | + }) |
| 18 | + |
| 19 | + it('passes Azure signing settings as separate Electron Builder arguments', () => { |
| 20 | + expect(windowsSigningArgs(signingEnvironment)).toEqual([ |
| 21 | + '--config.win.azureSignOptions.endpoint', 'https://example.test', |
| 22 | + '--config.win.azureSignOptions.codeSigningAccountName', 'signing-account', |
| 23 | + '--config.win.azureSignOptions.certificateProfileName', 'certificate-profile', |
| 24 | + '--config.win.azureSignOptions.publisherName', 'CN=Example Publisher, O=Example Publisher, L=Redmond, S=WA, C=US', |
| 25 | + ]) |
| 26 | + }) |
| 27 | + |
| 28 | + it('rejects a missing Azure credential', () => { |
| 29 | + expect(() => windowsSigningArgs({ |
| 30 | + ...signingEnvironment, |
| 31 | + AZURE_CLIENT_SECRET: undefined, |
| 32 | + })).toThrow( |
| 33 | + 'Windows signing is partially configured; missing: AZURE_CLIENT_SECRET. Set all seven signing variables or none.', |
| 34 | + ) |
| 35 | + }) |
| 36 | + |
| 37 | + it('rejects a missing Azure signing setting', () => { |
| 38 | + expect(() => windowsSigningArgs({ |
| 39 | + ...signingEnvironment, |
| 40 | + AZURE_SIGNING_ACCOUNT: undefined, |
| 41 | + })).toThrow( |
| 42 | + 'Windows signing is partially configured; missing: AZURE_SIGNING_ACCOUNT. Set all seven signing variables or none.', |
| 43 | + ) |
| 44 | + }) |
| 45 | + |
| 46 | + it('treats whitespace-only signing values as absent', () => { |
| 47 | + expect(() => windowsSigningArgs({ |
| 48 | + ...signingEnvironment, |
| 49 | + AZURE_SIGNING_PUBLISHER_NAME: ' ', |
| 50 | + })).toThrow('AZURE_SIGNING_PUBLISHER_NAME') |
| 51 | + }) |
| 52 | +}) |
| 53 | + |
| 54 | +describe('Windows package invocation', () => { |
| 55 | + it('quotes the publisher name on Windows', () => { |
| 56 | + const invocation = windowsPackageInvocation('win32', signingEnvironment, 'never') |
| 57 | + |
| 58 | + expect(invocation.args).toContain('"CN=Example Publisher, O=Example Publisher, L=Redmond, S=WA, C=US"') |
| 59 | + expect(invocation.shell).toBe(true) |
| 60 | + }) |
| 61 | + |
| 62 | + it('leaves the publisher name unquoted outside Windows', () => { |
| 63 | + const invocation = windowsPackageInvocation('darwin', signingEnvironment, 'never') |
| 64 | + |
| 65 | + expect(invocation.args).toContain('CN=Example Publisher, O=Example Publisher, L=Redmond, S=WA, C=US') |
| 66 | + expect(invocation.shell).toBe(false) |
| 67 | + }) |
| 68 | + |
| 69 | + it('preserves argument order and content outside Windows', () => { |
| 70 | + expect(windowsPackageInvocation('darwin', signingEnvironment, 'never').args).toEqual([ |
| 71 | + 'exec', 'electron-builder', '--win', 'nsis', '--x64', '--publish', 'never', |
| 72 | + '--config.win.azureSignOptions.endpoint', 'https://example.test', |
| 73 | + '--config.win.azureSignOptions.codeSigningAccountName', 'signing-account', |
| 74 | + '--config.win.azureSignOptions.certificateProfileName', 'certificate-profile', |
| 75 | + '--config.win.azureSignOptions.publisherName', 'CN=Example Publisher, O=Example Publisher, L=Redmond, S=WA, C=US', |
| 76 | + ]) |
| 77 | + }) |
| 78 | + |
| 79 | + it('omits signing arguments when signing is not configured', () => { |
| 80 | + const expectedArgs = ['exec', 'electron-builder', '--win', 'nsis', '--x64', '--publish', 'never'] |
| 81 | + const darwin = windowsPackageInvocation('darwin', {}, 'never') |
| 82 | + const win32 = windowsPackageInvocation('win32', {}, 'never') |
| 83 | + |
| 84 | + expect(darwin.args).toEqual(expectedArgs) |
| 85 | + expect(win32.args).toEqual(expectedArgs) |
| 86 | + expect(darwin.args.some(argument => argument.startsWith('--config.win.'))).toBe(false) |
| 87 | + expect(win32.args.some(argument => argument.startsWith('--config.win.'))).toBe(false) |
| 88 | + }) |
| 89 | + |
| 90 | + it('uses pnpm on both platforms', () => { |
| 91 | + expect(windowsPackageInvocation('darwin', signingEnvironment, 'never').command).toBe('pnpm') |
| 92 | + expect(windowsPackageInvocation('win32', signingEnvironment, 'never').command).toBe('pnpm') |
| 93 | + }) |
| 94 | +}) |
0 commit comments