Skip to content

Commit bc3f157

Browse files
committed
Tests: Build njs with QuickJS support.
1 parent f633d36 commit bc3f157

File tree

2 files changed

+92
-32
lines changed

2 files changed

+92
-32
lines changed

.github/workflows/ci-functional-perl.yml

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,63 @@ on:
66
workflow_dispatch:
77

88
jobs:
9+
build-njs:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
repository: nginx/nginx
15+
ref: release-1.27.4
16+
path: nginx
17+
- uses: actions/checkout@v4
18+
with:
19+
repository: bellard/quickjs
20+
path: quickjs
21+
- uses: actions/checkout@v4
22+
with:
23+
repository: nginx/njs
24+
path: njs
25+
26+
- name: Install dependencies
27+
run: |
28+
sudo apt-get update
29+
sudo apt-get install -y build-essential \
30+
libpcre3-dev zlib1g-dev libssl-dev \
31+
libxml2-dev libxslt-dev
32+
33+
- name: Build QuickJS
34+
working-directory: quickjs
35+
run: |
36+
CFLAGS='-fPIC' make libquickjs.a
37+
38+
- name: Build NJS module
39+
working-directory: nginx
40+
run: |
41+
./auto/configure \
42+
--add-dynamic-module=../njs/nginx \
43+
--with-cc-opt="-I../quickjs" \
44+
--with-ld-opt="-L../quickjs" \
45+
--with-compat
46+
make -j$(nproc) modules
47+
48+
- name: Upload build artifacts
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: njs-build
52+
path: nginx/objs/ngx_http_js_module.so
53+
954
test-njs-saml:
1055
runs-on: ubuntu-latest
56+
needs: build-njs
1157
steps:
1258
- name: Checkout repository
13-
uses: actions/checkout@v3
59+
uses: actions/checkout@v4
1460

1561
- name: Install prerequisites
1662
run: |
1763
sudo apt-get update
1864
sudo apt-get install -y apt-transport-https lsb-release apt-utils ubuntu-keyring gnupg2 \
19-
ca-certificates wget mercurial
65+
ca-certificates wget
2066
2167
- name: Prepare keys and certificates
2268
run: |
@@ -58,9 +104,18 @@ jobs:
58104
run: |
59105
git clone https://github.com/nginx/nginx-tests.git
60106
107+
- name: Download build artifacts
108+
uses: actions/download-artifact@v4
109+
with:
110+
name: njs-build
111+
path: ${{ runner.temp }}
112+
61113
- name: Run tests
62114
working-directory: t
63115
run: |
64-
PERL5LIB=../nginx-tests/lib TEST_NGINX_BINARY=/usr/sbin/nginx TEST_NGINX_VERBOSE=1 \
65-
TEST_NGINX_GLOBALS="load_module /etc/nginx/modules/ngx_http_js_module-debug.so; mgmt {license_token $RUNNER_TEMP/lic;}" \
116+
PERL5LIB=../nginx-tests/lib \
117+
TEST_NGINX_BINARY=/usr/sbin/nginx \
118+
TEST_NGINX_VERBOSE=1 \
119+
TEST_NGINX_GLOBALS="load_module $RUNNER_TEMP/ngx_http_js_module.so; mgmt {license_token $RUNNER_TEMP/lic;}" \
120+
TEST_NGINX_GLOBALS_HTTP="js_engine qjs;" \
66121
prove -v .

saml_sp.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
/*
22
* JavaScript functions for providing SAML SP with NGINX Plus
33
*
4-
* Copyright (C) 2023 Nginx, Inc.
4+
* Copyright (C) 2025 Nginx, Inc.
55
*/
66

7-
export default {
8-
handleSingleSignOn, // Process SAML Response form IdP
9-
handleSingleLogout, // Process SAML LogoutRequest and LogoutResponse from IdP
10-
handleAllMessages, // Process all SAML messages from IdP
11-
initiateSingleSignOn, // Initiate SAML SSO by redirecting to IdP
12-
initiateSingleLogout // Initiate SAML SLO by redirecting to IdP
13-
};
14-
15-
const xml = require("xml");
16-
const zlib = require("zlib");
17-
const querystring = require("querystring");
18-
const fs = require("fs");
7+
import xml from 'xml';
8+
import zlib from 'zlib';
9+
import querystring from 'querystring';
10+
import fs from 'fs';
1911

2012
const initiateSingleSignOn = produceSAMLMessage.bind(null, "AuthnRequest");
2113
const initiateSingleLogout = produceSAMLMessage.bind(null, "LogoutRequest");
@@ -124,7 +116,14 @@ async function handleSAMLMessage(messageType, r) {
124116
}
125117

126118
function samlError(r, http_code, id, e) {
127-
let msg = r.variables.saml_debug ? e.stack : "ReferenceError: " + e.message;
119+
let msg;
120+
121+
if (r.variables.saml_debug) {
122+
msg = `ReferenceError: ${e.message}\nStack: ${e.stack}`;
123+
} else {
124+
msg = `ReferenceError: ${e.message}`;
125+
}
126+
128127
r.error(`SAML SSO Error: ReferenceID: ${id} ${msg}`);
129128

130129
r.variables.internal_error_message += `ReferenceID: ${id}`;
@@ -1321,22 +1320,20 @@ function parseConfigurationOptions(r, messageType) {
13211320
}
13221321

13231322
function getEscapeXML() {
1324-
const fpc = Function.prototype.call;
1325-
const _replace = fpc.bind(fpc, String.prototype.replace);
1326-
1327-
const tbl = {
1328-
'<': '&lt;',
1329-
'>': '&gt;',
1330-
"'": '&apos;',
1331-
'"': '&quot;',
1332-
'&': '&amp;',
1323+
const escapeMap = {
1324+
'<': '&lt;',
1325+
'>': '&gt;',
1326+
"'": '&apos;',
1327+
'"': '&quot;',
1328+
'&': '&amp;'
13331329
};
1334-
tbl.__proto__ = null;
13351330

1336-
return function (str) {
1337-
return _replace(str, /[<>'"&]/g, c => tbl[c]);
1338-
}
1339-
};
1331+
return function escapeXML(str) {
1332+
if (str == null) return '';
1333+
1334+
return String(str).replace(/[<>'"&]/g, character => escapeMap[character]);
1335+
};
1336+
}
13401337

13411338
function isUrlOrUrn(str) {
13421339
const urlRegEx = /^((?:(?:https?):)\/\/)?((?:(?:[^:@]+(?::[^:@]+)?|[^:@]+@[^:@]+)(?::\d+)?)|(?:\[[a-fA-F0-9:]+]))(\/(?:[^?#]*))?(\\?(?:[^#]*))?(#(?:.*))?$/;
@@ -1373,3 +1370,11 @@ function readKeysFromFile(keyFile) {
13731370
throw Error(`Failed to read private or public key from file "${keyFile}": ${e.message}`);
13741371
}
13751372
}
1373+
1374+
export default {
1375+
handleSingleSignOn, // Process SAML Response form IdP
1376+
handleSingleLogout, // Process SAML LogoutRequest and LogoutResponse from IdP
1377+
handleAllMessages, // Process all SAML messages from IdP
1378+
initiateSingleSignOn, // Initiate SAML SSO by redirecting to IdP
1379+
initiateSingleLogout // Initiate SAML SLO by redirecting to IdP
1380+
};

0 commit comments

Comments
 (0)