-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] added connect option
ignoreAuthErrorAbort
which disables a c…
…onnection abort if client fails to authenticate twice with the same error.
- Loading branch information
Showing
5 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,15 +36,25 @@ import { | |
UserPass, | ||
} from "../src/mod.ts"; | ||
import { assertErrorCode, NatsServer } from "./helpers/mod.ts"; | ||
import { deferred, nkeys } from "../nats-base-client/internal_mod.ts"; | ||
import { NKeyAuth } from "../nats-base-client/authenticator.ts"; | ||
import { | ||
deferred, | ||
delay, | ||
NatsConnectionImpl, | ||
nkeys, | ||
} from "../nats-base-client/internal_mod.ts"; | ||
import { | ||
buildAuthenticator, | ||
NKeyAuth, | ||
} from "../nats-base-client/authenticator.ts"; | ||
import { assert } from "../nats-base-client/denobuffer.ts"; | ||
import { cleanup, setup } from "./jstest_util.ts"; | ||
import { | ||
encodeAccount, | ||
encodeOperator, | ||
encodeUser, | ||
} from "https://raw.githubusercontent.com/nats-io/jwt.js/main/src/jwt.ts"; | ||
import { Msg } from "https://deno.land/x/[email protected]/nats-base-client/types.ts"; | ||
import { DEFAULT_MAX_RECONNECT_ATTEMPTS } from "../nats-base-client/types.ts"; | ||
|
||
const conf = { | ||
authorization: { | ||
|
@@ -968,3 +978,46 @@ Deno.test("auth - perm sub iterator error", async () => { | |
|
||
await cleanup(ns, nc); | ||
}); | ||
|
||
Deno.test("auth - ignore auth error abort", async () => { | ||
const ns = await NatsServer.start({ | ||
authorization: { | ||
users: [{ | ||
user: "a", | ||
password: "a", | ||
}], | ||
}, | ||
}); | ||
async function t(ignoreAuthErrorAbort = false): Promise<number> { | ||
let pass = "a"; | ||
const authenticator = (): UserPass => { | ||
return { user: "a", pass }; | ||
}; | ||
const nc = await connect({ | ||
port: ns.port, | ||
authenticator, | ||
ignoreAuthErrorAbort, | ||
reconnectTimeWait: 150, | ||
}); | ||
|
||
let count = 0; | ||
(async () => { | ||
for await (const s of nc.status()) { | ||
if (s.type === "error" && s.data === "AUTHORIZATION_VIOLATION") { | ||
count++; | ||
} | ||
} | ||
})().then(); | ||
|
||
const nci = nc as NatsConnectionImpl; | ||
pass = "b"; | ||
nci.protocol.transport.disconnect(); | ||
|
||
await nc.closed(); | ||
return count; | ||
} | ||
|
||
assertEquals(await t(), 2); | ||
assertEquals(await t(true), DEFAULT_MAX_RECONNECT_ATTEMPTS); | ||
await ns.stop(); | ||
}); |