Skip to content

Commit 96cba10

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

File tree

2 files changed

+93
-32
lines changed

2 files changed

+93
-32
lines changed

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

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,64 @@ 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: xeioex/njs
24+
ref: release-0.8.10
25+
path: njs
26+
27+
- name: Install dependencies
28+
run: |
29+
sudo apt-get update
30+
sudo apt-get install -y build-essential \
31+
libpcre3-dev zlib1g-dev libssl-dev \
32+
libxml2-dev libxslt-dev
33+
34+
- name: Build QuickJS
35+
working-directory: quickjs
36+
run: |
37+
CFLAGS='-fPIC' make libquickjs.a
38+
39+
- name: Build NJS module
40+
working-directory: nginx
41+
run: |
42+
./auto/configure \
43+
--add-dynamic-module=../njs/nginx \
44+
--with-cc-opt="-I../quickjs" \
45+
--with-ld-opt="-L../quickjs" \
46+
--with-compat
47+
make -j$(nproc) modules
48+
49+
- name: Upload build artifacts
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: njs-build
53+
path: nginx/objs/ngx_http_js_module.so
54+
955
test-njs-saml:
1056
runs-on: ubuntu-latest
57+
needs: build-njs
1158
steps:
1259
- name: Checkout repository
13-
uses: actions/checkout@v3
60+
uses: actions/checkout@v4
1461

1562
- name: Install prerequisites
1663
run: |
1764
sudo apt-get update
1865
sudo apt-get install -y apt-transport-https lsb-release apt-utils ubuntu-keyring gnupg2 \
19-
ca-certificates wget mercurial
66+
ca-certificates wget
2067
2168
- name: Prepare keys and certificates
2269
run: |
@@ -58,9 +105,18 @@ jobs:
58105
run: |
59106
git clone https://github.com/nginx/nginx-tests.git
60107
108+
- name: Download build artifacts
109+
uses: actions/download-artifact@v4
110+
with:
111+
name: njs-build
112+
path: ${{ runner.temp }}
113+
61114
- name: Run tests
62115
working-directory: t
63116
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;}" \
117+
PERL5LIB=../nginx-tests/lib \
118+
TEST_NGINX_BINARY=/usr/sbin/nginx \
119+
TEST_NGINX_VERBOSE=1 \
120+
TEST_NGINX_GLOBALS="load_module $RUNNER_TEMP/ngx_http_js_module.so; mgmt {license_token $RUNNER_TEMP/lic;}" \
121+
TEST_NGINX_GLOBALS_HTTP="js_engine qjs;" \
66122
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)