|
1 |
| -import { describe, it, expect } from 'vitest' |
2 |
| -import { formatHost } from '../src/utils' |
| 1 | +import { describe, expect, it } from 'vitest' |
3 | 2 | import { defaultHost } from '../src/constant'
|
| 3 | +import { formatHost } from '../src/utils' |
4 | 4 |
|
5 | 5 | describe('formatHost Function Tests', () => {
|
6 | 6 | it('should return default URL for empty string', () => {
|
@@ -62,4 +62,33 @@ describe('formatHost Function Tests', () => {
|
62 | 62 | it('should handle trailing slash with only a port', () => {
|
63 | 63 | expect(formatHost(':56789/')).toBe('http://127.0.0.1:56789')
|
64 | 64 | })
|
| 65 | + |
| 66 | + // Basic Auth Tests |
| 67 | + it('should preserve username in URL', () => { |
| 68 | + expect(formatHost('http://user@localhost:1234')).toBe('http://user@localhost:1234') |
| 69 | + }) |
| 70 | + |
| 71 | + it('should preserve username and password in URL', () => { |
| 72 | + expect(formatHost('http://user:pass@localhost:5678')).toBe('http://user:pass@localhost:5678') |
| 73 | + }) |
| 74 | + |
| 75 | + it('should preserve username with default port', () => { |
| 76 | + expect(formatHost('http://user@localhost')).toBe('http://user@localhost:80') |
| 77 | + }) |
| 78 | + |
| 79 | + it('should preserve username and password with default port', () => { |
| 80 | + expect(formatHost('http://user:pass@localhost')).toBe('http://user:pass@localhost:80') |
| 81 | + }) |
| 82 | + |
| 83 | + it('should preserve basic auth with https', () => { |
| 84 | + expect(formatHost('https://user:[email protected]')).toBe('https://user:[email protected]:443') |
| 85 | + }) |
| 86 | + |
| 87 | + it('should preserve basic auth with domain and custom port', () => { |
| 88 | + expect(formatHost('http://admin:[email protected]:8080')).toBe('http://admin:[email protected]:8080') |
| 89 | + }) |
| 90 | + |
| 91 | + it('should preserve basic auth and remove trailing slash', () => { |
| 92 | + expect(formatHost('http://john:[email protected]:3000/')).toBe('http://john:[email protected]:3000') |
| 93 | + }) |
65 | 94 | })
|
0 commit comments