File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ def get_json(uri)
80
80
http . request ( request )
81
81
}
82
82
83
- unless response . kind_of? Net :: HTTPSuccess
83
+ unless response . code . to_i < 300
84
84
raise HTTPError , "Unexpected error response #{ response . code } : #{ response . body } "
85
85
end
86
86
@@ -115,7 +115,7 @@ def get_audit
115
115
return { } if body . empty?
116
116
117
117
response = post_json ( uri , body )
118
- unless response . kind_of? Net :: HTTPSuccess
118
+ unless response . code . to_i < 300
119
119
raise HTTPError , "Unexpected error response #{ response . code } : #{ response . body } "
120
120
end
121
121
JSON . parse ( response . body )
Original file line number Diff line number Diff line change @@ -67,6 +67,22 @@ class Importmap::NpmTest < ActiveSupport::TestCase
67
67
end
68
68
end
69
69
70
+ test "failed vulnerable packages with mock" do
71
+ response = Class . new do
72
+ def body
73
+ { "message" => "Service unavailable" } . to_json
74
+ end
75
+
76
+ def code ( ) "500" end
77
+ end . new
78
+
79
+ @npm . stub ( :post_json , response ) do
80
+ assert_raises ( Importmap ::Npm ::HTTPError ) do
81
+ vulnerable_packages = @npm . vulnerable_packages
82
+ end
83
+ end
84
+ end
85
+
70
86
test "successful vulnerable packages with mock" do
71
87
response = Class . new do
72
88
def body
You can’t perform that action at this time.
0 commit comments