Skip to content

Commit

Permalink
Merge pull request #34 from 0llirocks/33-cvss-prefix-is-missing-in-v310
Browse files Browse the repository at this point in the history
33 cvss prefix is missing in v310
  • Loading branch information
0llirocks authored Oct 15, 2023
2 parents 48e844d + 468d62e commit 1cb5093
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.1.1] - 2023-10-15

### Fixes
* CVSS prefix is missing in v3.1.0. Fixes [#33](https://github.com/0llirocks/cvss-suite/issues/33)

## [3.1.0] - 2022-09-27

### Fixes
Expand Down
12 changes: 7 additions & 5 deletions lib/cvss_suite/cvss.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CVSS-Suite, a Ruby gem to manage the CVSS vector
#
# Copyright (c) 2016-2022 Siemens AG
# Copyright (c) 2022 0llirocks
# Copyright (c) 2022-2023 0llirocks
#
# Authors:
# 0llirocks <http://0lli.rocks>
Expand All @@ -17,10 +17,6 @@ class Cvss
# Metric of a CVSS vector.
attr_reader :base, :temporal, :environmental

##
# Returns the vector itself.
attr_reader :vector

##
# Creates a new CVSS vector by a +vector+.
#
Expand Down Expand Up @@ -80,6 +76,12 @@ def overall_score
base_score
end

##
# Returns the vector itself.
def vector
@vector.to_s
end

private

def extract_metrics
Expand Down
8 changes: 7 additions & 1 deletion lib/cvss_suite/cvss3/cvss3.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CVSS-Suite, a Ruby gem to manage the CVSS vector
#
# Copyright (c) 2016-2022 Siemens AG
# Copyright (c) 2022 0llirocks
# Copyright (c) 2022-2023 0llirocks
#
# Authors:
# 0llirocks <http://0lli.rocks>
Expand Down Expand Up @@ -45,6 +45,12 @@ def environmental_score
Cvss3Helper.round_up(@environmental.score(@base, @temporal))
end

##
# Returns the vector itself.
def vector
"#{CvssSuite::CVSS_VECTOR_BEGINNINGS.find { |beginning| beginning[:version] == version }[:string]}#{@vector}"
end

private

def init_metrics
Expand Down
8 changes: 7 additions & 1 deletion lib/cvss_suite/cvss31/cvss31.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CVSS-Suite, a Ruby gem to manage the CVSS vector
#
# Copyright (c) 2019-2022 Siemens AG
# Copyright (c) 2022 0llirocks
# Copyright (c) 2022-2023 0llirocks
#
# Authors:
# 0llirocks <http://0lli.rocks>
Expand Down Expand Up @@ -50,6 +50,12 @@ def environmental_score
Cvss31Helper.round_up(@environmental.score(@base, @temporal))
end

##
# Returns the vector itself.
def vector
"#{CvssSuite::CVSS_VECTOR_BEGINNINGS.find { |beginning| beginning[:version] == version }[:string]}#{@vector}"
end

private

def init_metrics
Expand Down
4 changes: 2 additions & 2 deletions lib/cvss_suite/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CVSS-Suite, a Ruby gem to manage the CVSS vector
#
# Copyright (c) 2016-2022 Siemens AG
# Copyright (c) 2022 0llirocks
# Copyright (c) 2022-2023 0llirocks
#
# Authors:
# 0llirocks <http://0lli.rocks>
Expand All @@ -10,5 +10,5 @@
# See the LICENSE.md file in the top-level directory.

module CvssSuite
VERSION = '3.1.0'.freeze
VERSION = '3.1.1'.freeze
end
13 changes: 12 additions & 1 deletion spec/cvss2/cvss2_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CVSS-Suite, a Ruby gem to manage the CVSS vector
#
# Copyright (c) 2016-2022 Siemens AG
# Copyright (c) 2022 0llirocks
# Copyright (c) 2022-2023 0llirocks
#
# Authors:
# 0llirocks <http://0lli.rocks>
Expand Down Expand Up @@ -137,4 +137,15 @@
end
end
end

describe 'correct vector' do
[
['AV:N/AC:L/Au:N/C:P/I:P/A:P', 'AV:N/AC:L/Au:N/C:P/I:P/A:P'],
['(AV:N/AC:L/Au:N/C:P/I:P/A:P)', 'AV:N/AC:L/Au:N/C:P/I:P/A:P']
].each do |vector|
it "'#{vector[0]}' is expected to return '#{vector[1]}'" do
expect(CvssSuite.new(vector[0]).vector).to eq(vector[1])
end
end
end
end
17 changes: 16 additions & 1 deletion spec/cvss3/cvss3_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CVSS-Suite, a Ruby gem to manage the CVSS vector
#
# Copyright (c) 2016-2022 Siemens AG
# Copyright (c) 2022 0llirocks
# Copyright (c) 2022-2023 0llirocks
#
# Authors:
# 0llirocks <http://0lli.rocks>
Expand Down Expand Up @@ -160,4 +160,19 @@

it_behaves_like 'a invalid cvss vector with version', 3.0
end

describe 'correct vector' do
[
['CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:U/C:L/I:L/A:L', 'CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:U/C:L/I:L/A:L'],
['CVSS:3.0/A:L/AC:H/PR:L/UI:R/S:U/C:L/I:L/AV:L', 'CVSS:3.0/A:L/AC:H/PR:L/UI:R/S:U/C:L/I:L/AV:L'],
[
'CVSS:3.0/AV:P/AC:L/PR:H/UI:N/S:C/C:N/I:L/A:H/E:X/RL:T/RC:C/CR:M/IR:L/AR:H/MAV:X/MAC:X/MPR:X/MUI:X/MS:X/MC:X/MI:X/MA:X', # rubocop:disable Layout/LineLength
'CVSS:3.0/AV:P/AC:L/PR:H/UI:N/S:C/C:N/I:L/A:H/E:X/RL:T/RC:C/CR:M/IR:L/AR:H/MAV:X/MAC:X/MPR:X/MUI:X/MS:X/MC:X/MI:X/MA:X' # rubocop:disable Layout/LineLength
]
].each do |vector|
it "'#{vector[0]}' is expected to return '#{vector[1]}'" do
expect(CvssSuite.new(vector[0]).vector).to eq(vector[1])
end
end
end
end
17 changes: 16 additions & 1 deletion spec/cvss31/cvss31_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CVSS-Suite, a Ruby gem to manage the CVSS vector
#
# Copyright (c) 2016-2022 Siemens AG
# Copyright (c) 2022 0llirocks
# Copyright (c) 2022-2023 0llirocks
#
# Authors:
# 0llirocks <http://0lli.rocks>
Expand Down Expand Up @@ -159,4 +159,19 @@

it_behaves_like 'a invalid cvss vector with version', 3.1
end

describe 'correct vector' do
[
['CVSS:3.1/AV:L/AC:H/PR:L/UI:R/S:U/C:L/I:L/A:L', 'CVSS:3.1/AV:L/AC:H/PR:L/UI:R/S:U/C:L/I:L/A:L'],
['CVSS:3.1/A:L/AC:H/PR:L/UI:R/S:U/C:L/I:L/AV:L', 'CVSS:3.1/A:L/AC:H/PR:L/UI:R/S:U/C:L/I:L/AV:L'],
[
'CVSS:3.1/AV:P/AC:L/PR:H/UI:N/S:C/C:N/I:L/A:H/E:X/RL:T/RC:C/CR:M/IR:L/AR:H/MAV:X/MAC:X/MPR:X/MUI:X/MS:X/MC:X/MI:X/MA:X', # rubocop:disable Layout/LineLength
'CVSS:3.1/AV:P/AC:L/PR:H/UI:N/S:C/C:N/I:L/A:H/E:X/RL:T/RC:C/CR:M/IR:L/AR:H/MAV:X/MAC:X/MPR:X/MUI:X/MS:X/MC:X/MI:X/MA:X' # rubocop:disable Layout/LineLength
]
].each do |vector|
it "'#{vector[0]}' is expected to return '#{vector[1]}'" do
expect(CvssSuite.new(vector[0]).vector).to eq(vector[1])
end
end
end
end

0 comments on commit 1cb5093

Please sign in to comment.