Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ§ͺ Adds tests for header auth proxy whitelist matching

Alicia Sykes48eb1d8b4e45
diff --git a/tests/server/trusted-proxy.test.js b/tests/server/trusted-proxy.test.js
new file mode 100644
index 00000000..b59afc23
--- /dev/null
+++ b/tests/server/trusted-proxy.test.js
@@ -0,0 +1,18 @@
+// @vitest-environment node
+import { describe, it, expect } from 'vitest';
+
+const isTrustedProxy = require('../../services/utils/trusted-proxy');
+
+describe('isTrustedProxy', () => {
+ it('matches IPv4 proxies on a dual-stack socket', () => {
+ expect(isTrustedProxy(['172.18.0.2'], '::ffff:172.18.0.2')).toBe(true);
+ expect(isTrustedProxy(['::ffff:172.18.0.2'], '::ffff:172.18.0.2')).toBe(true);
+ expect(isTrustedProxy(['127.0.0.1'], '::1')).toBe(true);
+ });
+
+ it('rejects anything not on the list', () => {
+ expect(isTrustedProxy(['172.18.0.2'], '::ffff:172.18.0.3')).toBe(false);
+ expect(isTrustedProxy(['127.0.0.1'], '127.0.0.2')).toBe(false);
+ expect(isTrustedProxy([null], undefined)).toBe(false);
+ });
+});