Skip to content

Commit

Permalink
fix: match style of existing codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
markwylde committed Dec 4, 2023
1 parent e7e45bd commit 781df1a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
12 changes: 12 additions & 0 deletions demo/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MongoClient } from '../mod.ts';

for (let x = 0; x < 100000; x++) {
const client = new MongoClient();

const url = `mongodb://testadmin1:testpass1@localhost:27017?directConnection=true`
console.log('url:', url);
await client.connect(url);

await client.close()
console.log('');
}
2 changes: 1 addition & 1 deletion src/auth/scram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MongoDriverError } from "../error.ts";
import { b64, Binary, crypto as stdCrypto, Document, hex } from "../../deps.ts";
import { driverMetadata } from "../protocol/mod.ts";
import { pbkdf2 } from "./pbkdf2.ts";
import { decodeBase64 } from "../utils/decodeBase64.ts";
import { decodeBase64 } from "../utils/decode_base64.ts";

type CryptoMethod = "sha1" | "sha256";

Expand Down
File renamed without changes.
41 changes: 41 additions & 0 deletions tests/cases/11_decode_base64.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { decodeBase64 } from "../../src/utils/decode_base64.ts";

import { assertEquals, describe, it } from "./../test.deps.ts";

describe("decodeBase64", () => {
it({
name: "should correctly decode a standard base64 encoded string",
fn() {
const encoded = "SGVsbG8gV29ybGQ="; // "Hello World" in base64
const decoded = decodeBase64(encoded);
assertEquals(new TextDecoder().decode(decoded), "Hello World");
},
});

it({
name: "should correctly decode a URL-safe base64 encoded string",
fn() {
const encoded = "SGVsbG8tV29ybGRf"; // URL-safe base64 variant
const decoded = decodeBase64(encoded);
assertEquals(new TextDecoder().decode(decoded), "Hello-World_");
},
});

it({
name: "should handle base64 strings with missing padding",
fn() {
const encoded = "SGVsbG8gV29ybGQ"; // Missing '=' at the end
const decoded = decodeBase64(encoded);
assertEquals(new TextDecoder().decode(decoded), "Hello World");
},
});

it({
name: "should return an empty array for an empty string",
fn() {
const encoded = "";
const decoded = decodeBase64(encoded);
assertEquals(decoded.length, 0);
},
});
});

0 comments on commit 781df1a

Please sign in to comment.