Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,4 +50,4 @@ jobs:
- name: Install ruby dependencies
run: bundle install --jobs 4 --retry 3
- name: Validate YAML
run: bundle exec rake lint
run: USEKWALIFY="yes" bundle exec rake lint
1 change: 0 additions & 1 deletion Gemfile
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,6 @@ source 'https://rubygems.org'

gem 'rake'
gem 'faraday', '~> 2.0'
gem 'kwalify', '~> 0.1'
gem 'json_schemer', '~> 2.0'
gem 'rspec', '~> 3.0'

Expand Down
9 changes: 0 additions & 9 deletions spec/gem_advisory_example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,14 +51,5 @@
end
end

let(:schema_file) { File.join(__dir__, 'schemas/gem.yml') }

it "should have valid schema" do
schema = YAML.safe_load_file(schema_file)
validator = Kwalify::Validator.new(schema)
errors = validator.validate(advisory)

expect(errors).to be_empty
end
end
end
9 changes: 0 additions & 9 deletions spec/ruby_advisory_example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,14 +19,5 @@
end
end

let(:schema_file) { File.join(__dir__, 'schemas/ruby.yml') }

it "should have valid schema" do
schema = YAML.safe_load_file(schema_file)
validator = Kwalify::Validator.new(schema)
errors = validator.validate(advisory)

expect(errors).to be_empty
end
end
end
30 changes: 28 additions & 2 deletions spec/schema_validation_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,31 @@ def normalize_for_json(value)
end
end

def raw_yaml_field_checks(data)
errors = []

if data.key?('date') && !data['date'].is_a?(Date)
errors << {
'data_pointer' => '/date',
'error' => 'value must be a YAML date'
}
end

%w[cvss_v2 cvss_v3 cvss_v4].each do |field|
next unless data.key?(field)

value = data[field]
next if value.is_a?(Float)

errors << {
'data_pointer' => "/#{field}",
'error' => 'value must be a float'
}
end

errors
end

def format_errors(errors)
errors.map do |e|
pointer = e['data_pointer'].to_s.empty? ? '<root>' : e['data_pointer']
Expand All@@ -41,8 +66,9 @@ def format_errors(errors)
filename = path.split('/')[-2..].join('/')

it "#{filename} conforms to schema" do
data = normalize_for_json(YAML.safe_load_file(path, permitted_classes: [Date]))
errors = schemer.validate(data).to_a
raw_data = YAML.safe_load_file(path, permitted_classes: [Date])
data = normalize_for_json(raw_data)
errors = raw_yaml_field_checks(raw_data) + schemer.validate(data).to_a

expect(errors).to be_empty, lambda {
"#{filename}\n#{format_errors(errors)}"
Expand Down
9 changes: 0 additions & 9 deletions spec/spec_helper.rb
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
require 'strscan'

class StringScanner
def peep(len)
peek(len)
end
end

require 'date'
require 'kwalify'
require 'rspec'

ROOT = File.expand_path(File.join(__dir__,'..'))
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all \u003cpre\u003e\u003ccode\u003e blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks"); } } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); } })(); })();
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,4 +50,4 @@ jobs:
- name: Install ruby dependencies
run: bundle install --jobs 4 --retry 3
- name: Validate YAML
run: bundle exec rake lint
run: USEKWALIFY="yes" bundle exec rake lint
1 change: 0 additions & 1 deletion Gemfile
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,6 @@ source 'https://rubygems.org'

gem 'rake'
gem 'faraday', '~> 2.0'
gem 'kwalify', '~> 0.1'
gem 'json_schemer', '~> 2.0'
gem 'rspec', '~> 3.0'

Expand Down
9 changes: 0 additions & 9 deletions spec/gem_advisory_example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,14 +51,5 @@
end
end

let(:schema_file) { File.join(__dir__, 'schemas/gem.yml') }

it "should have valid schema" do
schema = YAML.safe_load_file(schema_file)
validator = Kwalify::Validator.new(schema)
errors = validator.validate(advisory)

expect(errors).to be_empty
end
end
end
9 changes: 0 additions & 9 deletions spec/ruby_advisory_example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,14 +19,5 @@
end
end

let(:schema_file) { File.join(__dir__, 'schemas/ruby.yml') }

it "should have valid schema" do
schema = YAML.safe_load_file(schema_file)
validator = Kwalify::Validator.new(schema)
errors = validator.validate(advisory)

expect(errors).to be_empty
end
end
end
30 changes: 28 additions & 2 deletions spec/schema_validation_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,31 @@ def normalize_for_json(value)
end
end

def raw_yaml_field_checks(data)
errors = []

if data.key?('date') && !data['date'].is_a?(Date)
errors << {
'data_pointer' => '/date',
'error' => 'value must be a YAML date'
}
end

%w[cvss_v2 cvss_v3 cvss_v4].each do |field|
next unless data.key?(field)

value = data[field]
next if value.is_a?(Float)

errors << {
'data_pointer' => "/#{field}",
'error' => 'value must be a float'
}
end

errors
end

def format_errors(errors)
errors.map do |e|
pointer = e['data_pointer'].to_s.empty? ? '<root>' : e['data_pointer']
Expand All@@ -41,8 +66,9 @@ def format_errors(errors)
filename = path.split('/')[-2..].join('/')

it "#{filename} conforms to schema" do
data = normalize_for_json(YAML.safe_load_file(path, permitted_classes: [Date]))
errors = schemer.validate(data).to_a
raw_data = YAML.safe_load_file(path, permitted_classes: [Date])
data = normalize_for_json(raw_data)
errors = raw_yaml_field_checks(raw_data) + schemer.validate(data).to_a

expect(errors).to be_empty, lambda {
"#{filename}\n#{format_errors(errors)}"
Expand Down
9 changes: 0 additions & 9 deletions spec/spec_helper.rb
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
require 'strscan'

class StringScanner
def peep(len)
peek(len)
end
end

require 'date'
require 'kwalify'
require 'rspec'

ROOT = File.expand_path(File.join(__dir__,'..'))