Skip to content

Commit

Permalink
fix: update tests and process gemspec files too
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Oct 8, 2019
1 parent 0127e0a commit da910fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
21 changes: 13 additions & 8 deletions src/lib/plugins/rubygems/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inspectors, Spec } from './inspectors';
import { MissingTargetFileError } from '../../errors/missing-targetfile-error';
import gemfileLockToDependencies = require('./gemfile-lock-to-dependencies');
import _ = require('lodash');
import * as _ from 'lodash';
import { MultiProjectResult } from '@snyk/cli-interface/legacy/plugin';

export async function inspect(
Expand All @@ -12,12 +12,6 @@ export async function inspect(
throw MissingTargetFileError(root);
}
const specs = await gatherSpecs(root, targetFile);
const gemfileLockBase64 = _.get(specs, 'files.gemfileLock.contents');
const gemfileLockContents = Buffer.from(
gemfileLockBase64,
'base64',
).toString();
const dependencies = gemfileLockToDependencies(gemfileLockContents);

return {
plugin: {
Expand All @@ -29,13 +23,24 @@ export async function inspect(
depTree: {
name: specs.packageName,
targetFile: specs.targetFile,
dependencies,
dependencies: getDependenciesFromSpecs(specs),
},
},
],
};
}

function getDependenciesFromSpecs(specs) {
const gemfileLockBase64 = _.get(specs, 'files.gemfileLock.contents');
const gemspecBase64 = _.get(specs, 'files.gemspec.contents');
const contents = Buffer.from(
gemfileLockBase64 || gemspecBase64,
'base64',
).toString();
const dependencies = gemfileLockToDependencies(contents);
return dependencies;
}

async function gatherSpecs(root, targetFile): Promise<Spec> {
for (const inspector of inspectors) {
if (inspector.canHandle(targetFile)) {
Expand Down
1 change: 0 additions & 1 deletion src/lib/snyk-test/run-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import snyk = require('../');
import spinner = require('../spinner');
import common = require('./common');
import { DepTree, TestOptions } from '../types';
import gemfileLockToDependencies = require('../../lib/plugins/rubygems/gemfile-lock-to-dependencies');
import {
convertTestDepGraphResultToLegacy,
AnnotatedIssue,
Expand Down
21 changes: 11 additions & 10 deletions test/acceptance/cli.acceptance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const after = tap.runOnly ? only : test;
// Should be after `process.env` setup.
import * as plugins from '../../src/lib/plugins';
import { legacyPlugin as pluginApi } from '@snyk/cli-interface';
import { fail } from 'assert';

function loadJson(filename: string) {
return JSON.parse(fs.readFileSync(filename, 'utf-8'));
Expand Down Expand Up @@ -281,8 +280,9 @@ test('`test ruby-app` meta when no vulns', async (t) => {
t.match(meta[0], /Organization:\s+test-org/, 'organization displayed');
t.match(meta[1], /Package manager:\s+rubygems/, 'package manager displayed');
t.match(meta[2], /Target file:\s+Gemfile/, 'target file displayed');
t.match(meta[3], /Open source:\s+no/, 'open source displayed');
t.match(meta[4], /Project path:\s+ruby-app/, 'path displayed');
t.match(meta[3], /Project name:\s+ruby-app/, 'project name displayed');
t.match(meta[4], /Open source:\s+no/, 'open source displayed');
t.match(meta[5], /Project path:\s+ruby-app/, 'path displayed');
t.notMatch(
meta[5],
/Local Snyk policy:\s+found/,
Expand Down Expand Up @@ -317,8 +317,13 @@ test('`test ruby-app-thresholds`', async (t) => {
'package manager displayed',
);
t.match(meta[2], /Target file:\s+Gemfile/, 'target file displayed');
t.match(meta[3], /Open source:\s+no/, 'open source displayed');
t.match(meta[4], /Project path:\s+ruby-app-thresholds/, 'path displayed');
t.match(
meta[3],
/Project name:\s+ruby-app-thresholds/,
'project name displayed',
);
t.match(meta[4], /Open source:\s+no/, 'open source displayed');
t.match(meta[5], /Project path:\s+ruby-app-thresholds/, 'path displayed');
t.notMatch(
meta[5],
/Local Snyk policy:\s+found/,
Expand Down Expand Up @@ -3295,11 +3300,7 @@ test('`monitor ruby-app`', async (t) => {
);
t.match(req.url, '/monitor/rubygems', 'puts at correct url');
t.notOk(req.body.targetFile, 'doesnt send the targetFile');
t.match(
decode64(req.body.package.files.gemfileLock.contents),
'remote: http://rubygems.org/',
'attaches Gemfile.lock',
);
t.ok(req.body.package.dependencies, 'dependencies sent instead of files');
});

test('`monitor maven-app`', async (t) => {
Expand Down

0 comments on commit da910fa

Please sign in to comment.