Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong when expect toEqual #10785

Open
nguyenvanvy1999 opened this issue May 3, 2024 · 3 comments
Open

Wrong when expect toEqual #10785

nguyenvanvy1999 opened this issue May 3, 2024 · 3 comments
Labels
bug Something isn't working crash An issue that could cause a crash

Comments

@nguyenvanvy1999
Copy link

How can we reproduce the crash?

Code:

export const aes256Encrypt = (
	data: string | Record<string, any> | Record<string, any>[],
	key: string,
	iv: string,
): string => {
	const cipher: Cipher = crypto.createCipheriv(env.JWT_ENCRYPT_METHOD, key, iv);
	return Buffer.from(
		cipher.update(JSON.stringify(data), "utf8", "hex") + cipher.final("hex"),
	).toString("base64");
};

export const aes256Decrypt = <
	T extends string | Record<string, any> | Record<string, any>[],
>(
	encrypted: string,
	key: string,
	iv: string,
): T => {
	const buff: Buffer = Buffer.from(encrypted, "base64");
	const decipher: Decipher = crypto.createDecipheriv(
		env.JWT_ENCRYPT_METHOD,
		key,
		iv,
	);
	return JSON.parse(
		decipher.update(buff.toString("utf8"), "hex", "utf8") +
			decipher.final("utf8"),
	);
};

And test case what is wrong:

		it("Should encrypt and decrypt object data", (): void => {
			const data: Record<string, any> = { for: "bar", bar: 1 };
			const encrypted: string = aes256Encrypt(data, key, iv);
			expect(typeof encrypted).toBe("string");
			const decrypt: Record<string, any> = aes256Decrypt<Record<string, any>>(
				encrypted,
				key,
				iv,
			);
			console.log(decrypt);
			console.log(data);
			expect(typeof decrypt).toBe("object");
			expect(decrypt).toEqual(data);
		});

I think the issue on end expect: expect(decrypt).toEqual(data);

Relevant log output

No response

Stack Trace (bun.report)

Bun v1.1.6 (e58d67b) on macos x86_64 [TestCommand]

Illegal instruction at address 0x7FF81BD51E93

  • 2 unknown/js code
  • pas_thread_local_cache_flush_deallocation_log
  • pas_thread_local_cache_get_local_allocator_slow
  • pas_segregated_view_get_page_config
  • bmalloc_heap_config_specialized_try_allocate_common_impl_slow
  • bmalloc_try_allocate_auxiliary_impl_casual_case(...)
  • WTF::Detail::CallableWrapper<Bun::signalHandler(...)::$_0, void, WebCore::ScriptExecutionContext&>::call
  • 1 unknown/js code
  • JSC::ASTBuilder::Expression JSC::Parser<JSC::Lexer<unsigned char> >::parseVariableDeclarationList<JSC::ASTBuilder>
@nguyenvanvy1999 nguyenvanvy1999 added bug Something isn't working crash An issue that could cause a crash labels May 3, 2024
@nguyenvanvy1999 nguyenvanvy1999 changed the title Wrong when testing with decryptASC256 Wrong when expect toEqual May 3, 2024
@Jarred-Sumner
Copy link
Collaborator

@nguyenvanvy1999 can you provide a more complete reproduction?

@nguyenvanvy1999
Copy link
Author

Hello @Jarred-Sumner .So sorry but after that crash, I can not reproduction any time. I was not change any code, but it work now. So weird. Btw, thanks about your feedback

@nguyenvanvy1999
Copy link
Author

nguyenvanvy1999 commented May 3, 2024

Of course, you can see my test case on this repository: https://github.com/nguyenvanvy1999/elysia/blob/main/test/util/token.test.ts
Test case was crash from line 57 - 68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash An issue that could cause a crash
Projects
None yet
Development

No branches or pull requests

2 participants