Conditions | 4 |
Total Lines | 109 |
Code Lines | 87 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* Vuls - Vulnerability Scanner |
||
185 | func TestContentConvertVinfos(t *testing.T) { |
||
186 | |||
187 | var tests = []struct { |
||
188 | in1 string |
||
189 | in2 WpStatus |
||
190 | expected []models.VulnInfo |
||
191 | }{ |
||
192 | { |
||
193 | in1: "{\"4.9.4\":{\"release_date\":\"2018-02-06\",\"changelog_url\":\"https://codex.wordpress.org/Version_4.9.4\",\"status\":\"insecure\",\"vulnerabilities\":[{\"id\":9021,\"title\":\"WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)\",\"created_at\":\"2018-02-05T16:50:40.000Z\",\"updated_at\":\"2018-08-29T19:13:04.000Z\",\"published_date\":\"2018-02-05T00:00:00.000Z\",\"vuln_type\":\"DOS\",\"references\":{\"url\":[\"https://baraktawily.blogspot.fr/2018/02/how-to-dos-29-of-world-wide-websites.html\",\"https://github.com/quitten/doser.py\",\"https://thehackernews.com/2018/02/wordpress-dos-exploit.html\"],\"cve\":[\"2018-6389\"]},\"fixed_in\": null}]}}", |
||
194 | in2: WpStatus{Name: "twentyfifteen", Status: "inactive", Update: "available", Version: "1.1"}, |
||
195 | expected: []models.VulnInfo{ |
||
196 | { |
||
197 | CveID: "CVE-2018-6389", |
||
198 | Confidences: models.Confidences{}, |
||
199 | AffectedPackages: models.PackageStatuses{ |
||
200 | models.PackageStatus{ |
||
201 | Name: "", |
||
202 | NotFixedYet: true, |
||
203 | FixState: "", |
||
204 | }, |
||
205 | }, |
||
206 | DistroAdvisories: []models.DistroAdvisory{}, |
||
207 | CpeURIs: []string{}, |
||
208 | CveContents: models.NewCveContents( |
||
209 | models.CveContent{ |
||
210 | Type: "", |
||
211 | CveID: "CVE-2018-6389", |
||
212 | Title: "WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)", |
||
213 | Summary: "", |
||
214 | Cvss2Score: 0.000000, |
||
215 | Cvss2Vector: "", |
||
216 | Cvss2Severity: "", |
||
217 | Cvss3Score: 0.000000, |
||
218 | Cvss3Vector: "", |
||
219 | Cvss3Severity: "", |
||
220 | SourceLink: "", |
||
221 | Cpes: []models.Cpe{}, |
||
222 | References: models.References{}, |
||
223 | CweIDs: []string{}, |
||
224 | Published: time.Time{}, |
||
225 | LastModified: time.Time{}, |
||
226 | Mitigation: "", |
||
227 | Optional: map[string]string{}, |
||
228 | }, |
||
229 | ), |
||
230 | Exploits: []models.Exploit{}, |
||
231 | AlertDict: models.AlertDict{ |
||
232 | Ja: []alert.Alert{}, |
||
233 | En: []alert.Alert{}, |
||
234 | }, |
||
235 | }, |
||
236 | }, |
||
237 | }, |
||
238 | { |
||
239 | in1: "{\"4.9.4\":{\"release_date\":\"2018-02-06\",\"changelog_url\":\"https://codex.wordpress.org/Version_4.9.4\",\"status\":\"insecure\",\"vulnerabilities\":[{\"id\":9021,\"title\":\"WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)\",\"created_at\":\"2018-02-05T16:50:40.000Z\",\"updated_at\":\"2018-08-29T19:13:04.000Z\",\"published_date\":\"2018-02-05T00:00:00.000Z\",\"vuln_type\":\"DOS\",\"references\":{\"url\":[\"https://baraktawily.blogspot.fr/2018/02/how-to-dos-29-of-world-wide-websites.html\",\"https://github.com/quitten/doser.py\",\"https://thehackernews.com/2018/02/wordpress-dos-exploit.html\"],\"cve\":[\"2018-6389\"]},\"fixed_in\": \"1.0\"}]}}", |
||
240 | in2: WpStatus{Name: "twentyfifteen", Status: "inactive", Update: "available", Version: "1.1"}, |
||
241 | expected: []models.VulnInfo{}, |
||
242 | }, |
||
243 | { |
||
244 | in1: "{\"4.9.4\":{\"release_date\":\"2018-02-06\",\"changelog_url\":\"https://codex.wordpress.org/Version_4.9.4\",\"status\":\"insecure\",\"vulnerabilities\":[{\"id\":9021,\"title\":\"WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)\",\"created_at\":\"2018-02-05T16:50:40.000Z\",\"updated_at\":\"2018-08-29T19:13:04.000Z\",\"published_date\":\"2018-02-05T00:00:00.000Z\",\"vuln_type\":\"DOS\",\"references\":{\"url\":[\"https://baraktawily.blogspot.fr/2018/02/how-to-dos-29-of-world-wide-websites.html\",\"https://github.com/quitten/doser.py\",\"https://thehackernews.com/2018/02/wordpress-dos-exploit.html\"],\"cve\":[\"2018-6389\"]},\"fixed_in\": \"1.2\"}]}}", |
||
245 | in2: WpStatus{Name: "twentyfifteen", Status: "inactive", Update: "available", Version: "1.1"}, |
||
246 | expected: []models.VulnInfo{ |
||
247 | { |
||
248 | CveID: "CVE-2018-6389", |
||
249 | Confidences: models.Confidences{}, |
||
250 | AffectedPackages: models.PackageStatuses{ |
||
251 | models.PackageStatus{ |
||
252 | Name: "", |
||
253 | NotFixedYet: false, |
||
254 | FixState: "", |
||
255 | }, |
||
256 | }, |
||
257 | DistroAdvisories: []models.DistroAdvisory{}, |
||
258 | CpeURIs: []string{}, |
||
259 | CveContents: models.NewCveContents( |
||
260 | models.CveContent{ |
||
261 | Type: "", |
||
262 | CveID: "CVE-2018-6389", |
||
263 | Title: "WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)", |
||
264 | Summary: "", |
||
265 | Cvss2Score: 0.000000, |
||
266 | Cvss2Vector: "", |
||
267 | Cvss2Severity: "", |
||
268 | Cvss3Score: 0.000000, |
||
269 | Cvss3Vector: "", |
||
270 | Cvss3Severity: "", |
||
271 | SourceLink: "", |
||
272 | Cpes: []models.Cpe{}, |
||
273 | References: models.References{}, |
||
274 | CweIDs: []string{}, |
||
275 | Published: time.Time{}, |
||
276 | LastModified: time.Time{}, |
||
277 | Mitigation: "", |
||
278 | Optional: map[string]string{}, |
||
279 | }, |
||
280 | ), |
||
281 | Exploits: []models.Exploit{}, |
||
282 | AlertDict: models.AlertDict{ |
||
283 | Ja: []alert.Alert{}, |
||
284 | En: []alert.Alert{}, |
||
285 | }, |
||
286 | }, |
||
287 | }, |
||
288 | }, |
||
289 | } |
||
290 | for _, test := range tests { |
||
291 | actual, _ := contentConvertVinfos(test.in1, test.in2) |
||
292 | if !reflect.DeepEqual(test.expected, actual) { |
||
293 | t.Errorf("expected %v, actual %v", test.expected, actual) |
||
294 | } |
||
355 |