papers 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ## 2.0.0 (current release)
3
+ ## 2.0.1 (current release)
4
+
5
+ * Correct validation of js.erb and coffee.erb files.
6
+
7
+ ## 2.0.0
4
8
 
5
9
  * Make the `version_whitelisted_license` option to apply to Bower components.
6
10
  This is a breaking change since current manifests with whitelisted licenses
@@ -25,7 +25,8 @@ module Papers
25
25
  'LGPLv3',
26
26
  'Ruby',
27
27
  'Manually Reviewed',
28
- 'Unlicensed'
28
+ 'Unlicensed',
29
+ 'ISC'
29
30
  ]
30
31
 
31
32
  @version_whitelisted_license = nil
@@ -15,7 +15,7 @@ module Papers
15
15
 
16
16
  # TODO: add logic for determining rails. Is Rails.root better than Dir.pwd for such a case?
17
17
  root_regexp = /^#{Regexp.escape Dir.pwd.to_s}\//
18
- files = dirs.map { |dir| Dir.glob("#{dir}/**/*.{js,coffee}") }.flatten.map do |name|
18
+ files = dirs.map { |dir| Dir.glob("#{dir}/**/*.{js,js.erb,coffee,coffee.erb}") }.flatten.map do |name|
19
19
  name = name.sub(root_regexp, '')
20
20
  name unless whitelist_dirs.any? { |dir| name.start_with?(dir) }
21
21
  end
@@ -1,7 +1,7 @@
1
1
  module Papers
2
2
  class Version
3
3
  MAJOR = 2
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
 
7
7
  def self.to_s
@@ -5,7 +5,7 @@ require_relative '../lib/papers'
5
5
  describe 'NpmPackageSpecification' do
6
6
  describe '#full_introspected_entries' do
7
7
  it 'reads dependencies from the specified file' do
8
- Papers::Configuration.any_instance.stub(:npm_package_json_path).and_return('spec/support/package.json')
8
+ allow_any_instance_of(Papers::Configuration).to receive(:npm_package_json_path).and_return('spec/support/package.json')
9
9
 
10
10
  expect(Papers::NpmPackage.full_introspected_entries).to eq([
11
11
  {"name"=>"prod_dependency", "version"=>"3.2.0"},
@@ -18,14 +18,15 @@ describe 'NpmPackageSpecification' do
18
18
  end
19
19
 
20
20
  it "raises an error when package.json does not parse properly" do
21
- Papers::Configuration.any_instance.stub(:npm_package_json_path).and_return('spec/support/package_with_error.json')
21
+ allow_any_instance_of(Papers::Configuration).to receive(:npm_package_json_path).and_return('spec/support/package_with_error.json')
22
22
  expect { Papers::NpmPackage.full_introspected_entries }.to raise_error JSON::ParserError
23
23
  end
24
24
 
25
25
  it 'combines dependencies and devDependencies' do
26
- Papers::NpmPackage.stub(:package)
27
- .and_return({'dependencies' => {'prod_package' => '~> 1.2.3'},
28
- 'devDependencies' => {'dev_package' => '~> 1.2.0'}})
26
+ allow(Papers::NpmPackage).to receive(:package).and_return({
27
+ 'dependencies' => { 'prod_package' => '~> 1.2.3' },
28
+ 'devDependencies' => {'dev_package' => '~> 1.2.0'}
29
+ })
29
30
 
30
31
 
31
32
  expect(Papers::NpmPackage.full_introspected_entries).to eq([
@@ -35,8 +36,9 @@ describe 'NpmPackageSpecification' do
35
36
  end
36
37
 
37
38
  it 'returns dependencies when devDependencies is not defined' do
38
- Papers::NpmPackage.stub(:package)
39
- .and_return({'dependencies' => {'npm_package' => '1.2.3'}})
39
+ allow(Papers::NpmPackage).to receive(:package).and_return({
40
+ 'dependencies' => { 'npm_package' => '1.2.3' }
41
+ })
40
42
 
41
43
  expect(Papers::NpmPackage.full_introspected_entries).to eq([{
42
44
  'name' => 'npm_package',
@@ -45,8 +47,9 @@ describe 'NpmPackageSpecification' do
45
47
  end
46
48
 
47
49
  it 'returns devDependencies when dependencies is not defined' do
48
- Papers::NpmPackage.stub(:package)
49
- .and_return({'devDependencies' => {'npm_package' => '1.2.3'}})
50
+ allow(Papers::NpmPackage).to receive(:package).and_return({
51
+ 'devDependencies' => { 'npm_package' => '1.2.3' }
52
+ })
50
53
 
51
54
  expect(Papers::NpmPackage.full_introspected_entries).to eq([{
52
55
  'name' => 'npm_package',
@@ -55,8 +58,9 @@ describe 'NpmPackageSpecification' do
55
58
  end
56
59
 
57
60
  it 'removes leading non-digits from the version' do
58
- Papers::NpmPackage.stub(:package)
59
- .and_return({'dependencies' => {'npm_package' => '~> 1.2.3'}})
61
+ allow(Papers::NpmPackage).to receive(:package).and_return({
62
+ 'dependencies' => { 'npm_package' => '~> 1.2.3' }
63
+ })
60
64
 
61
65
  expect(Papers::NpmPackage.full_introspected_entries).to eq([{
62
66
  'name' => 'npm_package',
@@ -65,8 +69,7 @@ describe 'NpmPackageSpecification' do
65
69
  end
66
70
 
67
71
  it 'returns an empty array when the dependencies and devDependencies keys are not defined' do
68
- Papers::NpmPackage.stub(:package)
69
- .and_return({})
72
+ allow(Papers::NpmPackage).to receive(:package).and_return({})
70
73
 
71
74
  expect(Papers::NpmPackage.full_introspected_entries).to eq([])
72
75
  end
@@ -74,18 +77,18 @@ describe 'NpmPackageSpecification' do
74
77
 
75
78
  describe "#introspected" do
76
79
  it "returns an array of name-version strings" do
77
- Papers::NpmPackage.stub(:full_introspected_entries)
78
- .and_return([{
79
- 'name' => 'npm_package',
80
- 'version' => '1.2.3'
81
- }])
80
+ allow(Papers::NpmPackage).to receive(:full_introspected_entries).and_return([
81
+ {
82
+ 'name' => 'npm_package',
83
+ 'version' => '1.2.3'
84
+ }
85
+ ])
82
86
 
83
87
  expect(Papers::NpmPackage.introspected).to eq(["npm_package-1.2.3"])
84
88
  end
85
89
 
86
90
  it "returns an empty array when the dependencies key is not defined" do
87
- Papers::NpmPackage.stub(:full_introspected_entries)
88
- .and_return([])
91
+ allow(Papers::NpmPackage).to receive(:full_introspected_entries).and_return([])
89
92
 
90
93
  expect(Papers::NpmPackage.introspected).to eq([])
91
94
  end
data/spec/papers_spec.rb CHANGED
@@ -7,24 +7,25 @@ describe 'Papers' do
7
7
  let(:validator) { Papers::LicenseValidator.new }
8
8
 
9
9
  it 'validates a manifest with empty values and set of dependencies' do
10
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
10
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
11
11
  'javascripts' => {},
12
12
  'gems' => {}
13
13
  })
14
- Papers::Gem.stub(:introspected).and_return([])
14
+ allow(Papers::Gem).to receive(:introspected).and_return([])
15
15
 
16
16
  expect(validator.valid?).to be_truthy
17
17
  end
18
18
 
19
19
  it 'detects mismatched gems' do
20
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
20
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
21
21
  'javascripts' => {},
22
22
  'gems' => {
23
23
  'foo-1.2' => { 'license' => 'MIT' },
24
24
  'baz-1.3' => { 'license' => 'BSD' }
25
25
  }
26
26
  })
27
- Bundler.stub_chain(:load, :specs).and_return([
27
+
28
+ allow(Bundler).to receive_message_chain(:load, :specs).and_return([
28
29
  double(name: 'bar', version: '1.2', licenses: ['MIT']),
29
30
  double(name: 'baz', version: '1.3', licenses: ['BSD'])
30
31
  ])
@@ -40,16 +41,15 @@ describe 'Papers' do
40
41
  end
41
42
 
42
43
  it 'detects mismatched gem versions' do
43
- Papers::Configuration.any_instance.stub(:validate_javascript?).and_return(false)
44
-
45
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
44
+ allow_any_instance_of(Papers::Configuration).to receive(:validate_javascript?).and_return(false)
45
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
46
46
  'javascripts' => {},
47
47
  'gems' => {
48
48
  'foo-1.2' => { 'license' => 'MIT' },
49
49
  'baz-1.3' => { 'license' => 'BSD' }
50
50
  }
51
51
  })
52
- Bundler.stub_chain(:load, :specs).and_return([
52
+ allow(Bundler).to receive_message_chain(:load, :specs).and_return([
53
53
  double(name: 'foo', version: '1.2', licenses: ['MIT']),
54
54
  double(name: 'baz', version: '1.2', licenses: ['BSD'])
55
55
  ])
@@ -64,16 +64,15 @@ describe 'Papers' do
64
64
  end
65
65
 
66
66
  it 'detects omitted gem versions' do
67
- Papers::Configuration.any_instance.stub(:validate_javascript?).and_return(false)
68
-
69
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
67
+ allow_any_instance_of(Papers::Configuration).to receive(:validate_javascript?).and_return(false)
68
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
70
69
  'javascripts' => {},
71
70
  'gems' => {
72
71
  'foo' => { 'license' => 'MIT' },
73
72
  'baz-1.2' => { 'license' => 'BSD' }
74
73
  }
75
74
  })
76
- Bundler.stub_chain(:load, :specs).and_return([
75
+ allow(Bundler).to receive_message_chain(:load, :specs).and_return([
77
76
  double(name: 'foo', version: '1.2', licenses: ['MIT']),
78
77
  double(name: 'baz', version: '1.2', licenses: ['BSD'])
79
78
  ])
@@ -88,14 +87,14 @@ describe 'Papers' do
88
87
  end
89
88
 
90
89
  it 'is OK with matching gem sets' do
91
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
90
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
92
91
  'javascripts' => {},
93
92
  'gems' => {
94
93
  'foo-1.2' => { 'license' => 'MIT' },
95
94
  'baz-1.2' => { 'license' => 'BSD' }
96
95
  }
97
96
  })
98
- Bundler.stub_chain(:load, :specs).and_return([
97
+ allow(Bundler).to receive_message_chain(:load, :specs).and_return([
99
98
  double(name: 'foo', version: '1.2', licenses: ['MIT']),
100
99
  double(name: 'baz', version: '1.2', licenses: ['BSD'])
101
100
  ])
@@ -104,18 +103,18 @@ describe 'Papers' do
104
103
  end
105
104
 
106
105
  it 'is OK with whitelisting gem versions on a specific license' do
107
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
106
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
108
107
  'javascripts' => {},
109
108
  'gems' => {
110
109
  'foo' => { 'license' => 'MIT' },
111
110
  'baz' => { 'license' => 'BSD' }
112
111
  }
113
112
  })
114
- Bundler.stub_chain(:load, :specs).and_return([
113
+ allow(Bundler).to receive_message_chain(:load, :specs).and_return([
115
114
  double(name: 'foo', version: '1.2', licenses: ['MIT']),
116
115
  double(name: 'baz', version: '1.2', licenses: ['BSD'])
117
116
  ])
118
- Papers::Configuration.any_instance.stub(:version_whitelisted_license).and_return('MIT')
117
+ allow_any_instance_of(Papers::Configuration).to receive(:version_whitelisted_license).and_return('MIT')
119
118
 
120
119
  expect(validator).not_to be_valid
121
120
  expect(validator.errors).to eq([
@@ -125,14 +124,14 @@ describe 'Papers' do
125
124
  end
126
125
 
127
126
  it 'is OK with matching gem sets but complain about a license issue' do
128
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
127
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
129
128
  'javascripts' => {},
130
129
  'gems' => {
131
130
  'foo-1.2' => { 'license' => 'MIT' },
132
131
  'baz-1.3' => { 'license' => 'GPL' }
133
132
  }
134
133
  })
135
- Bundler.stub_chain(:load, :specs).and_return([
134
+ allow(Bundler).to receive_message_chain(:load, :specs).and_return([
136
135
  double(name: 'foo', version: '1.2', licenses: ['MIT']),
137
136
  double(name: 'baz', version: '1.3', licenses: ['GPL'])
138
137
  ])
@@ -145,7 +144,7 @@ describe 'Papers' do
145
144
  end
146
145
 
147
146
  it 'displays gem licenses in a pretty format without versions' do
148
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
147
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
149
148
  'javascripts' => {},
150
149
  'gems' => {
151
150
  'foo-1.2' => { 'license' => 'MIT' },
@@ -177,14 +176,24 @@ describe 'Papers' do
177
176
  end
178
177
 
179
178
  it 'displays JS libraries in a pretty format without versions' do
180
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
179
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
181
180
  'javascripts' => {
182
181
  '/path/to/foo.js' => {
183
182
  'license' => 'MIT',
184
183
  'license_url' => nil,
185
184
  'project_url' => nil
186
185
  },
187
- '/path/to/newrelic.js' => {
186
+ '/path/to/bar.coffee' => {
187
+ 'license' => 'MIT',
188
+ 'license_url' => nil,
189
+ 'project_url' => nil
190
+ },
191
+ '/path/to/newrelic.js.erb' => {
192
+ 'license' => 'New Relic',
193
+ 'license_url' => nil,
194
+ 'project_url' => nil
195
+ },
196
+ '/path/to/newrelic.js.coffee' => {
188
197
  'license' => 'New Relic',
189
198
  'license_url' => nil,
190
199
  'project_url' => nil
@@ -193,7 +202,7 @@ describe 'Papers' do
193
202
  'gems' => {}
194
203
  })
195
204
 
196
- expect(validator.pretty_js_list).to eq([
205
+ expect(validator.pretty_js_list).to contain_exactly(
197
206
  {
198
207
  :name =>'/path/to/foo.js',
199
208
  :license =>'MIT',
@@ -201,18 +210,30 @@ describe 'Papers' do
201
210
  :project_url => nil
202
211
  },
203
212
  {
204
- :name =>'/path/to/newrelic.js',
213
+ :name =>'/path/to/bar.coffee',
214
+ :license =>'MIT',
215
+ :license_url => nil,
216
+ :project_url => nil
217
+ },
218
+ {
219
+ :name =>'/path/to/newrelic.js.erb',
220
+ :license =>'New Relic',
221
+ :license_url => nil,
222
+ :project_url => nil
223
+ },
224
+ {
225
+ :name =>'/path/to/newrelic.js.coffee',
205
226
  :license =>'New Relic',
206
227
  :license_url => nil,
207
228
  :project_url => nil
208
229
  }
209
- ])
230
+ )
210
231
  end
211
232
 
212
233
  it 'displays bower component licenses in a pretty format without versions' do
213
- Papers::Configuration.any_instance.stub(:validate_bower_components?).and_return(true)
234
+ allow_any_instance_of(Papers::Configuration).to receive(:validate_bower_components?).and_return(true)
214
235
 
215
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
236
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
216
237
  'javascripts' => {},
217
238
  'gems' => {},
218
239
  'bower_components' => {
@@ -257,9 +278,9 @@ describe 'Papers' do
257
278
  end
258
279
 
259
280
  it 'skips bower versions for whitelisted licenses' do
260
- Papers::Configuration.any_instance.stub(:version_whitelisted_license).and_return('Whitelist')
281
+ allow_any_instance_of(Papers::Configuration).to receive(:version_whitelisted_license).and_return('Whitelist')
261
282
 
262
- Papers::BowerComponent.stub(:bower_json_entries).and_return([
283
+ allow(Papers::BowerComponent).to receive(:bower_json_entries).and_return([
263
284
  {
264
285
  'name' => 'foo',
265
286
  '_release' => '1.2',
@@ -286,9 +307,9 @@ describe 'Papers' do
286
307
  end
287
308
 
288
309
  it 'displays npm package licenses in a pretty format without versions' do
289
- Papers::Configuration.any_instance.stub(:validate_npm_packages?).and_return(true)
310
+ allow_any_instance_of(Papers::Configuration).to receive(:validate_npm_packages?).and_return(true)
290
311
 
291
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
312
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
292
313
  'javascripts' => {},
293
314
  'gems' => {},
294
315
  'npm_packages' => {
@@ -339,13 +360,14 @@ describe 'Papers' do
339
360
 
340
361
  it 'is OK with whitelisting javascript javascript_paths' do
341
362
  # contents of javascript dir and no gems
342
- Dir.stub(:glob){[
363
+ allow(Dir).to receive(:glob).and_return([
343
364
  'app/javascripts/node_modules/should_be_whitelisted.js',
344
365
  'app/javascripts/test.js'
345
- ]}
346
- Papers::Gem.stub(:introspected).and_return([])
366
+ ])
367
+
368
+ allow(Papers::Gem).to receive(:introspected).and_return([])
347
369
 
348
- Papers::LicenseValidator.any_instance.stub(:manifest).and_return({
370
+ allow_any_instance_of(Papers::LicenseValidator).to receive(:manifest).and_return({
349
371
  'javascripts' => {
350
372
  'app/javascripts/test.js' => {
351
373
  'license' => 'MIT',
@@ -355,10 +377,10 @@ describe 'Papers' do
355
377
  },
356
378
  'gems' => {}
357
379
  })
358
- Papers::Configuration.any_instance.stub(:javascript_paths).and_return(['app/javascripts/'])
380
+ allow_any_instance_of(Papers::Configuration).to receive(:javascript_paths).and_return(['app/javascripts/'])
359
381
 
360
382
  # whitelist this directory
361
- Papers::Configuration.any_instance.stub(:whitelist_javascript_paths).and_return(['app/javascripts/node_modules'])
383
+ allow_any_instance_of(Papers::Configuration).to receive(:whitelist_javascript_paths).and_return(['app/javascripts/node_modules'])
362
384
 
363
385
  expect(Papers::Javascript.introspected).to_not include('app/javascripts/node_modules/should_be_whitelisted.js')
364
386
  expect(validator).to be_valid
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Ralph Bodenner
@@ -12,36 +13,40 @@ authors:
12
13
  autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
- date: 2014-10-07 00:00:00.000000000 Z
16
+ date: 2015-03-04 00:00:00.000000000 Z
16
17
  dependencies:
17
18
  - !ruby/object:Gem::Dependency
18
- version_requirements: !ruby/object:Gem::Requirement
19
+ name: rake
20
+ requirement: !ruby/object:Gem::Requirement
21
+ none: false
19
22
  requirements:
20
23
  - - ! '>='
21
24
  - !ruby/object:Gem::Version
22
25
  version: '0'
26
+ type: :development
23
27
  prerelease: false
24
- name: rake
25
- requirement: !ruby/object:Gem::Requirement
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ none: false
26
30
  requirements:
27
31
  - - ! '>='
28
32
  - !ruby/object:Gem::Version
29
33
  version: '0'
30
- type: :development
31
34
  - !ruby/object:Gem::Dependency
32
- version_requirements: !ruby/object:Gem::Requirement
35
+ name: rspec
36
+ requirement: !ruby/object:Gem::Requirement
37
+ none: false
33
38
  requirements:
34
39
  - - ~>
35
40
  - !ruby/object:Gem::Version
36
41
  version: 3.1.0
42
+ type: :development
37
43
  prerelease: false
38
- name: rspec
39
- requirement: !ruby/object:Gem::Requirement
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ none: false
40
46
  requirements:
41
47
  - - ~>
42
48
  - !ruby/object:Gem::Version
43
49
  version: 3.1.0
44
- type: :development
45
50
  description: ! 'Validate that the licenses used by your Ruby project''s dependencies
46
51
  (both gems
47
52
 
@@ -83,26 +88,27 @@ files:
83
88
  homepage: http://github.com/newrelic/papers
84
89
  licenses:
85
90
  - MIT
86
- metadata: {}
87
91
  post_install_message:
88
92
  rdoc_options: []
89
93
  require_paths:
90
94
  - lib
91
95
  required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
92
97
  requirements:
93
98
  - - ! '>='
94
99
  - !ruby/object:Gem::Version
95
100
  version: '0'
96
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
97
103
  requirements:
98
104
  - - ! '>='
99
105
  - !ruby/object:Gem::Version
100
106
  version: '0'
101
107
  requirements: []
102
108
  rubyforge_project:
103
- rubygems_version: 2.2.1
109
+ rubygems_version: 1.8.23
104
110
  signing_key:
105
- specification_version: 4
111
+ specification_version: 3
106
112
  summary: Validate the licenses of software dependencies you use
107
113
  test_files:
108
114
  - spec/npm_package_spec.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NjQ2MjU3NGM4OTljMjA2MGVlYjhiNzg5ZTk5YzZjOWM3NDZlMTBhMQ==
5
- data.tar.gz: !binary |-
6
- OWQ1OGJkY2FlMzQ0OTJmZDNkMGM1Y2FiZDE4M2JhYjc5MTY0ZDk3Mw==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- MzA3ZWM0ZWRlOGZlYTE2MTVkMjA3YTc3ZDNhODI1ZDY0NDk4M2UxN2E5OGM5
10
- MjUwNDU1ZjA0ZTZiMzVmMDUxZGU0NjQ5ZGNiYmE1ZmNhMzIxYzMxYTA1NjBm
11
- YzJiZWIxMDFlNzMzMmMwYzdlOGQyYWFlZmMyODJmMzU4NzFiOTE=
12
- data.tar.gz: !binary |-
13
- MDNiMjVjNjc2OTAwZjlmOTQ3OTk1MzJhOTRmZDY1OTY0ZDRjNjVjNDBjZDAw
14
- MzgwYmRlNDYxYjk0N2E4ZWMyYjIwZmQwNzM1YTc2YjAyNDdiODE3ZDgwODNi
15
- YWZjY2NhYTE5MTlhOWU4MWJlNDg1M2YyNjUxNmM0OTQ0ZGM4MDE=