cpe 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.3.0
data/cpe.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cpe"
8
- s.version = "0.1.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris Wuest"]
12
- s.date = "2012-02-24"
12
+ s.date = "2012-02-27"
13
13
  s.description = "Library for parsing and generating Common Platform Enumeration strings (see http://cpe.mitre.org/)"
14
14
  s.email = "chris@chriswuest.com"
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,8 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "cpe.gemspec",
27
27
  "lib/cpe.rb",
28
+ "test/cpe-test-invalid",
29
+ "test/cpe-test-valid",
28
30
  "test/helper.rb",
29
31
  "test/test_cpe.rb"
30
32
  ]
data/lib/cpe.rb CHANGED
@@ -3,6 +3,19 @@
3
3
  # Copyright (c) Chris Wuest <chris@chriswuest.com>
4
4
  # Expectr is freely distributable under the terms of an MIT-style license.
5
5
  # See LICENSE.txt or http://www.opensource.org/licenses/mit-license.php.
6
+ #
7
+
8
+ # Fixes for Ruby pre-1.9
9
+ if RUBY_VERSION =~ /^1.[^9]/
10
+ #
11
+ # Ruby does not implement KeyError before 1.9
12
+ #
13
+ class KeyError < IndexError
14
+ def initialize message = nil
15
+ super message || "Key not found"
16
+ end
17
+ end
18
+ end
6
19
 
7
20
  # == Description
8
21
  # Cpe is a small library built to simplify working with the Common Platform
@@ -64,19 +77,24 @@ class Cpe
64
77
  return ["cpe", @part, @vendor, @product, @version, @update, @edition, @language].join(":").downcase
65
78
  end
66
79
 
80
+ #
81
+ # Test for equality of generated CPE strings
82
+ def == cpe
83
+ raise ArgumentError unless cpe.kind_of? Cpe
84
+ self.generate == cpe.generate
85
+ end
86
+
67
87
  #
68
88
  # Parse pre-existing CPE string and return new Cpe object
69
89
  #
70
- # String parsing is permissive regarding the number of trailing colons
90
+ # String parsing is permissive regarding the number of trailing colons and whitespace
71
91
  # provided, filling in empty strings if needed.
72
92
  #
73
- # === Bugs
74
- #
75
- # * Presently unable to pass File object as input
76
- #
77
93
  def Cpe.parse cpe
78
- raise ArgumentError unless cpe.kind_of? String
79
- raise ArgumentError, "CPE malformed" unless /^cpe:\/[hoa]:/.match cpe and !/ /.match cpe
94
+ raise ArgumentError unless cpe.kind_of? String or cpe.kind_of? File
95
+ cpe = cpe.read if cpe.kind_of? File
96
+ cpe = cpe.downcase.chomp
97
+ raise ArgumentError, "CPE malformed" unless /^cpe:\/[hoa]:/.match cpe and !/[\s\n]/.match cpe
80
98
 
81
99
  data = Hash.new
82
100
  discard, data[:part], data[:vendor], data[:product], data[:version],
@@ -0,0 +1 @@
1
+ cpe:/i:redhat:enterprise_linux:3::as
@@ -0,0 +1 @@
1
+ cpe:/o:redhat:enterprise_linux:3
data/test/test_cpe.rb CHANGED
@@ -34,6 +34,9 @@ class TestCpe < Test::Unit::TestCase
34
34
  cpe = Cpe.new :part => Cpe::Hardware, :vendor => "cisco", :product => "router", :version => 3825
35
35
  assert_equal cpe.generate, "cpe:/h:cisco:router:3825:::"
36
36
 
37
+ assert_nothing_raised { Cpe.parse File.open('test/cpe-test-valid') }
38
+ assert_raises(ArgumentError) { Cpe.parse File.open('test/cpe-test-invalid') }
39
+
37
40
  assert_raises(ArgumentError) { Cpe.new :part => 2 }
38
41
  assert_nothing_raised { Cpe.new }
39
42
 
@@ -42,4 +45,13 @@ class TestCpe < Test::Unit::TestCase
42
45
  assert_raises(KeyError) { Cpe.new(:vendor => "redhat").generate }
43
46
  assert_nothing_raised { Cpe.new(:vendor => "redhat", :part => Cpe::OS).generate }
44
47
  end
48
+
49
+ def test_equality
50
+ cpe_a = Cpe.new :part => Cpe::OS, :vendor => "redhat", :product => "enterprise_linux", :version => 3
51
+ cpe_b = Cpe.parse "cpe:/o:redhat:enterprise_linux:3"
52
+ cpe_c = Cpe.parse File.open('test/cpe-test-valid')
53
+
54
+ assert_equal cpe_a, cpe_b
55
+ assert_equal cpe_a, cpe_c
56
+ end
45
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-24 00:00:00.000000000 Z
12
+ date: 2012-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
16
- requirement: &25157560 !ruby/object:Gem::Requirement
16
+ requirement: &8605640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *25157560
24
+ version_requirements: *8605640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &25157000 !ruby/object:Gem::Requirement
27
+ requirement: &8674700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.12'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *25157000
35
+ version_requirements: *8674700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &25156280 !ruby/object:Gem::Requirement
38
+ requirement: &8673600 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *25156280
46
+ version_requirements: *8673600
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &25155580 !ruby/object:Gem::Requirement
49
+ requirement: &8672980 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 1.8.3
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *25155580
57
+ version_requirements: *8672980
58
58
  description: Library for parsing and generating Common Platform Enumeration strings
59
59
  (see http://cpe.mitre.org/)
60
60
  email: chris@chriswuest.com
@@ -72,6 +72,8 @@ files:
72
72
  - VERSION
73
73
  - cpe.gemspec
74
74
  - lib/cpe.rb
75
+ - test/cpe-test-invalid
76
+ - test/cpe-test-valid
75
77
  - test/helper.rb
76
78
  - test/test_cpe.rb
77
79
  homepage: http://github.com/cwuest/ruby-cpe
@@ -89,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
91
  version: '0'
90
92
  segments:
91
93
  - 0
92
- hash: -2763396924108230200
94
+ hash: -2413955384257435782
93
95
  required_rubygems_version: !ruby/object:Gem::Requirement
94
96
  none: false
95
97
  requirements: