Skip to content

Commit 3e5e9e2

Browse files
committed
[FIX] added fix from #701
1 parent b3e1e13 commit 3e5e9e2

File tree

5 files changed

+79
-23
lines changed

5 files changed

+79
-23
lines changed

bin/cjs-fix-imports.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parseArgs } from "jsr:@std/[email protected]/parse-args"
1+
import { parseArgs } from "jsr:@std/[email protected]/parse-args";
22
import {
33
basename,
44
extname,
@@ -7,21 +7,19 @@ import {
77
} from "https://deno.land/[email protected]/path/mod.ts";
88

99
const argv = parseArgs(
10-
Deno.args,
11-
{
12-
alias: {
13-
o: ["out"],
14-
},
15-
boolean: true,
16-
string: ["out"],
17-
default: {
18-
o: "lib",
19-
},
10+
Deno.args,
11+
{
12+
alias: {
13+
o: ["out"],
2014
},
15+
boolean: true,
16+
string: ["out"],
17+
default: {
18+
o: "lib",
19+
},
20+
},
2121
);
2222

23-
24-
2523
// resolve the specified directories to fq
2624
let dirs = (argv._ as string[]).map((n) => {
2725
return resolve(n);
@@ -51,27 +49,26 @@ if (argv.debug) {
5149

5250
if (!dirs.length || argv.h || argv.help) {
5351
console.log(
54-
`deno run --allow-all cjs-fix-imports [--debug] [--out build/] dir/ dir2/`,
52+
`deno run --allow-all cjs-fix-imports [--debug] [--out build/] dir/ dir2/`,
5553
);
5654
Deno.exit(1);
5755
}
5856

5957
// create out if not exist
6058
await Deno.lstat(out)
61-
.catch(async () => {
62-
await Deno.mkdir(out);
63-
});
59+
.catch(async () => {
60+
await Deno.mkdir(out);
61+
});
6462

6563
// process each file - remove extensions from requires/import
6664
for (const fn of files) {
6765
const data = await Deno.readFile(fn);
6866
let txt = new TextDecoder().decode(data);
6967

70-
7168
let mod = txt.replace(/jsr:@nats-io\/nkeys/gim, "nkeys.js");
7269
mod = mod.replace(/jsr:@nats-io\/nuid/gim, "nuid");
73-
mod = mod.replace(/jsr:@nats-io\/nats-core/gim, "@nats-io/nats-core")
74-
if(!fn.endsWith("nkeys.ts") && !fn.endsWith("nuid.ts")) {
70+
mod = mod.replace(/jsr:@nats-io\/nats-core/gim, "@nats-io/nats-core");
71+
if (!fn.endsWith("nkeys.ts") && !fn.endsWith("nuid.ts")) {
7572
mod = mod.replace(/from\s+"(\S+).[t|j]s"/gim, 'from "$1"');
7673
}
7774

nats-base-client/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class NatsError extends Error {
142142
message: string;
143143
// TODO: on major version this should change to a number/enum
144144
code: string;
145-
permissionContext?: { operation: string; subject: string };
145+
permissionContext?: { operation: string; subject: string; queue?: string };
146146
chainedError?: Error;
147147
// these are for supporting jetstream
148148
api_error?: ApiError;

nats-base-client/protocol.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export class Subscriptions {
338338
let sub;
339339
if (ctx.operation === "subscription") {
340340
sub = subs.find((s) => {
341-
return s.subject === ctx.subject;
341+
return s.subject === ctx.subject && s.queue === ctx.queue;
342342
});
343343
}
344344
if (ctx.operation === "publish") {
@@ -696,7 +696,13 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
696696
err.permissionContext = {
697697
operation: m[1].toLowerCase(),
698698
subject: m[2],
699+
queue: undefined,
699700
};
701+
702+
const qm = s.match(/using queue "(\S+)"/);
703+
if (qm) {
704+
err.permissionContext.queue = qm[1];
705+
}
700706
}
701707
return err;
702708
} else if (t.indexOf("authorization violation") !== -1) {

nats-base-client/tests/auth_test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
assertArrayIncludes,
2424
assertEquals,
2525
assertRejects,
26+
assertStringIncludes,
2627
fail,
2728
} from "jsr:@std/assert";
2829
import { connect } from "./connect.ts";
@@ -1257,3 +1258,51 @@ Deno.test("auth - request context", async () => {
12571258

12581259
await cleanup(ns, nc, a);
12591260
});
1261+
1262+
Deno.test("auth - sub permission reload", async () => {
1263+
const conf = {
1264+
authorization: {
1265+
users: [{
1266+
user: "a",
1267+
password: "a",
1268+
permissions: { subscribe: ["q A", "h"] },
1269+
}],
1270+
},
1271+
};
1272+
1273+
const { ns, nc } = await _setup(connect, conf, {
1274+
user: "a",
1275+
pass: "a",
1276+
debug: true,
1277+
});
1278+
1279+
const qA = deferred();
1280+
nc.subscribe("q", {
1281+
queue: "A",
1282+
callback: (err, msg) => {
1283+
if (err) {
1284+
qA.reject(err);
1285+
}
1286+
},
1287+
});
1288+
1289+
const qBad = deferred<NatsError>();
1290+
nc.subscribe("q", {
1291+
queue: "bad",
1292+
callback: (err, msg) => {
1293+
if (err) {
1294+
qBad.resolve(err);
1295+
}
1296+
},
1297+
});
1298+
await nc.flush();
1299+
1300+
const err = await qBad;
1301+
qA.resolve();
1302+
1303+
await qA;
1304+
1305+
assertEquals(err.code, ErrorCode.PermissionsViolation);
1306+
assertStringIncludes(err.message, 'using queue "bad"');
1307+
await cleanup(ns, nc);
1308+
});

test_helpers/launcher.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,11 @@ export function toConf(o: any, indent?: string): string {
803803
buf.push(`${pad}${k}: ${v}`);
804804
}
805805
} else {
806-
buf.push(pad + v);
806+
if(v.includes(" ")) {
807+
buf.push(`${pad}"${v}"`)
808+
} else {
809+
buf.push(pad + v);
810+
}
807811
}
808812
}
809813
}

0 commit comments

Comments
 (0)