|
@@ -1,6 +1,6 @@
|
|
|
-import { describe, it, expect } from 'vitest'
|
|
|
-import { formatHost } from '../src/utils'
|
|
|
+import { describe, expect, it } from 'vitest'
|
|
|
import { defaultHost } from '../src/constant'
|
|
|
+import { formatHost } from '../src/utils'
|
|
|
|
|
|
describe('formatHost Function Tests', () => {
|
|
|
it('should return default URL for empty string', () => {
|
|
@@ -62,4 +62,33 @@ describe('formatHost Function Tests', () => {
|
|
|
it('should handle trailing slash with only a port', () => {
|
|
|
expect(formatHost(':56789/')).toBe('http://127.0.0.1:56789')
|
|
|
})
|
|
|
+
|
|
|
+ // Basic Auth Tests
|
|
|
+ it('should preserve username in URL', () => {
|
|
|
+ expect(formatHost('http://user@localhost:1234')).toBe('http://user@localhost:1234')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should preserve username and password in URL', () => {
|
|
|
+ expect(formatHost('http://user:pass@localhost:5678')).toBe('http://user:pass@localhost:5678')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should preserve username with default port', () => {
|
|
|
+ expect(formatHost('http://user@localhost')).toBe('http://user@localhost:80')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should preserve username and password with default port', () => {
|
|
|
+ expect(formatHost('http://user:pass@localhost')).toBe('http://user:pass@localhost:80')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should preserve basic auth with https', () => {
|
|
|
+ expect(formatHost('https://user:secret@secure.com')).toBe('https://user:secret@secure.com:443')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should preserve basic auth with domain and custom port', () => {
|
|
|
+ expect(formatHost('http://admin:1234@example.com:8080')).toBe('http://admin:1234@example.com:8080')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should preserve basic auth and remove trailing slash', () => {
|
|
|
+ expect(formatHost('http://john:doe@site.com:3000/')).toBe('http://john:doe@site.com:3000')
|
|
|
+ })
|
|
|
})
|