Skip to content
Snippets Groups Projects
Select Git revision
  • 2669079c2051f3f8635007f5e4d9ac934e9f8005
  • main default protected
  • release-please--branches--main--components--csi-driver
  • v2.16.0 protected
  • v2.15.0 protected
  • v2.14.0 protected
  • v2.13.0 protected
  • v2.12.0 protected
  • v2.11.0 protected
  • v2.10.1 protected
  • v2.10.0 protected
  • v2.9.0 protected
  • v2.8.0 protected
  • v2.7.1 protected
  • v2.7.0 protected
  • v2.6.0 protected
  • v2.5.1 protected
  • v2.5.0 protected
  • v2.4.0 protected
  • v2.3.2 protected
  • v2.3.1 protected
  • v2.3.0 protected
  • v2.3.0-rc.0 protected
23 results

README.md

Blame
  • vulnerabilities.spec.ts 1.94 KiB
    import type { Ecosystem, OsvOffline } from '@jamiemagee/osv-offline';
    import { mockFn } from 'jest-mock-extended';
    import { getConfig } from '../../../../test/util';
    import type { PackageFile } from '../../../modules/manager/types';
    import { Vulnerabilities } from './vulnerabilities';
    
    const getVulnerabilitiesMock =
      mockFn<typeof OsvOffline.prototype.getVulnerabilities>();
    const createMock = jest.fn();
    
    jest.mock('@jamiemagee/osv-offline', () => {
      return {
        __esModule: true,
        OsvOffline: class {
          static create() {
            return createMock();
          }
        },
      };
    });
    
    describe('workers/repository/process/vulnerabilities', () => {
      describe('create()', () => {
        it('works', async () => {
          await expect(Vulnerabilities.create()).resolves.not.toThrow();
        });
    
        it('throws when osv-offline error', async () => {
          createMock.mockRejectedValue(new Error());
    
          await expect(Vulnerabilities.create()).rejects.toThrow();
        });
      });
    
      describe('fetchVulnerabilities()', () => {
        const config = getConfig();
        const packageFiles: Record<string, PackageFile[]> = {
          npm: [{ deps: [{ depName: 'lodash' }] }],
        };
        let vulnerabilities: Vulnerabilities;
    
        beforeAll(async () => {
          createMock.mockResolvedValue({
            getVulnerabilities: (ecosystem: Ecosystem, packageName: string) =>
              getVulnerabilitiesMock(ecosystem, packageName),
          });
          vulnerabilities = await Vulnerabilities.create();
        });
    
        it('works', async () => {
          getVulnerabilitiesMock.mockResolvedValue([
            {
              id: 'ABCD',
              modified: new Date(),
              affected: [
                {
                  ranges: [{ type: 'SEMVER', events: [{ fixed: '1.2.3' }] }],
                  package: { name: 'lodash', ecosystem: 'npm' },
                },
              ],
            },
          ]);
    
          await vulnerabilities.fetchVulnerabilities(config, packageFiles);
    
          expect(config.packageRules).toHaveLength(1);
        });
      });
    });