Skip to content
Snippets Groups Projects
Select Git revision
  • 7afc2b75d5a7396ae130359f05722210d7de146d
  • main default protected
  • next
  • renovate/main-redis-5.x
  • chore/update-static-data
  • feat/gnupg
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • 41.62.4
  • 41.62.3
  • 41.62.2
  • 41.62.1
  • 41.62.0
  • 41.61.1
  • 41.61.0
  • 41.60.4
  • 41.60.3
  • 41.60.2
  • 41.60.1
  • 41.60.0
  • 41.59.2
  • 41.59.1
  • 41.59.0
  • 41.58.2
  • 41.58.1
  • 41.58.0
  • 41.57.1
  • 41.57.0
41 results

url.spec.ts

Blame
  • user avatar
    Sergei Zharinov authored and GitHub committed
    5f4b9f9a
    History
    url.spec.ts 2.84 KiB
    import { hostRules } from '../../../test/util';
    import { getHttpUrl, getRemoteUrlWithToken } from './url';
    
    jest.mock('../host-rules');
    
    describe('util/git/url', () => {
      describe('getHttpUrl()', () => {
        it('returns https url for git url', () => {
          expect(getHttpUrl('git://foo.bar/')).toBe('https://foo.bar/');
        });
    
        it('returns https url for https url', () => {
          expect(getHttpUrl('https://foo.bar/')).toBe('https://foo.bar/');
        });
    
        it('returns http url for http url', () => {
          expect(getHttpUrl('http://foo.bar/')).toBe('http://foo.bar/');
        });
      });
    
      describe('getRemoteUrlWithToken()', () => {
        it('returns original url if no host rule is found', () => {
          expect(getRemoteUrlWithToken('https://foo.bar/')).toBe(
            'https://foo.bar/'
          );
        });
    
        it('returns http url with token', () => {
          hostRules.find.mockReturnValueOnce({ token: 'token' });
          expect(getRemoteUrlWithToken('http://foo.bar/')).toBe(
            'http://token@foo.bar/'
          );
        });
    
        it('returns https url with token', () => {
          hostRules.find.mockReturnValueOnce({ token: 'token' });
          expect(getRemoteUrlWithToken('https://foo.bar/')).toBe(
            'https://token@foo.bar/'
          );
        });
    
        it('returns https url with token for non-http protocols', () => {
          hostRules.find.mockReturnValueOnce({ token: 'token' });
          expect(getRemoteUrlWithToken('ssh://foo.bar/')).toBe(
            'https://token@foo.bar/'
          );
        });
    
        it('returns https url with encoded token', () => {
          hostRules.find.mockReturnValueOnce({ token: 't#ken' });
          expect(getRemoteUrlWithToken('https://foo.bar/')).toBe(
            'https://t%23ken@foo.bar/'
          );
        });
    
        it('returns http url with username and password', () => {
          hostRules.find.mockReturnValueOnce({
            username: 'user',
            password: 'pass',
          });
          expect(getRemoteUrlWithToken('http://foo.bar/')).toBe(
            'http://user:pass@foo.bar/'
          );
        });
    
        it('returns https url with username and password', () => {
          hostRules.find.mockReturnValueOnce({
            username: 'user',
            password: 'pass',
          });
          expect(getRemoteUrlWithToken('https://foo.bar/')).toBe(
            'https://user:pass@foo.bar/'
          );
        });
    
        it('returns https url with username and password for non-http protocols', () => {
          hostRules.find.mockReturnValueOnce({
            username: 'user',
            password: 'pass',
          });
          expect(getRemoteUrlWithToken('ssh://foo.bar/')).toBe(
            'https://user:pass@foo.bar/'
          );
        });
    
        it('returns https url with encoded username and password', () => {
          hostRules.find.mockReturnValueOnce({
            username: 'u$er',
            password: 'p@ss',
          });
          expect(getRemoteUrlWithToken('https://foo.bar/')).toBe(
            'https://u%24er:p%40ss@foo.bar/'
          );
        });
      });
    });