Conditions | 4 |
Total Lines | 139 |
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\" |
||
194 | :\"https://codex.wordpress.org/Version_4.9.4\",\"status\":\"insecur |
||
195 | e\",\"vulnerabilities\":[{\"id\":9021,\"title\":\"WordPress <= 4.9. |
||
196 | 4 - Application Denial of Service (DoS) (unpatched)\",\"created_at\ |
||
197 | ":\"2018-02-05T16:50:40.000Z\",\"updated_at\":\"2018-08-29T19:13:04 |
||
198 | .000Z\",\"published_date\":\"2018-02-05T00:00:00.000Z\",\"vuln_type |
||
199 | \":\"DOS\",\"references\":{\"url\":[\"https://baraktawily.blogspot. |
||
200 | fr/2018/02/how-to-dos-29-of-world-wide-websites.html\",\"https://gi |
||
201 | thub.com/quitten/doser.py\",\"https://thehackernews.com/2018/02/wor |
||
202 | dpress-dos-exploit.html\"],\"cve\":[\"2018-6389\"]},\"fixed_in\":nu |
||
203 | ll}]}}`, |
||
204 | in2: WpStatus{Name: "twentyfifteen", Status: "inactive", Update: "available", Version: "1.1"}, |
||
205 | expected: []models.VulnInfo{ |
||
206 | { |
||
207 | CveID: "CVE-2018-6389", |
||
208 | Confidences: models.Confidences{}, |
||
209 | AffectedPackages: models.PackageStatuses{ |
||
210 | models.PackageStatus{ |
||
211 | Name: "", |
||
212 | NotFixedYet: false, |
||
213 | FixState: "", |
||
214 | }, |
||
215 | }, |
||
216 | DistroAdvisories: []models.DistroAdvisory{}, |
||
217 | CpeURIs: []string{}, |
||
218 | CveContents: models.NewCveContents( |
||
219 | models.CveContent{ |
||
220 | Type: "", |
||
221 | CveID: "CVE-2018-6389", |
||
222 | Title: "WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)", |
||
223 | Summary: "", |
||
224 | Cvss2Score: 0.000000, |
||
225 | Cvss2Vector: "", |
||
226 | Cvss2Severity: "", |
||
227 | Cvss3Score: 0.000000, |
||
228 | Cvss3Vector: "", |
||
229 | Cvss3Severity: "", |
||
230 | SourceLink: "", |
||
231 | Cpes: []models.Cpe{}, |
||
232 | References: models.References{}, |
||
233 | CweIDs: []string{}, |
||
234 | Published: time.Time{}, |
||
235 | LastModified: time.Time{}, |
||
236 | Mitigation: "", |
||
237 | Optional: map[string]string{}, |
||
238 | }, |
||
239 | ), |
||
240 | Exploits: []models.Exploit{}, |
||
241 | AlertDict: models.AlertDict{ |
||
242 | Ja: []alert.Alert{}, |
||
243 | En: []alert.Alert{}, |
||
244 | }, |
||
245 | }, |
||
246 | }, |
||
247 | }, |
||
248 | { |
||
249 | in1: `{\"4.9.4\":{\"release_date\":\"2018-02-06\",\"changelog_url\" |
||
250 | :\"https://codex.wordpress.org/Version_4.9.4\",\"status\":\"insecur |
||
251 | e\",\"vulnerabilities\":[{\"id\":9021,\"title\":\"WordPress <= 4.9. |
||
252 | 4 - Application Denial of Service (DoS) (unpatched)\",\"created_at\ |
||
253 | ":\"2018-02-05T16:50:40.000Z\",\"updated_at\":\"2018-08-29T19:13:04 |
||
254 | .000Z\",\"published_date\":\"2018-02-05T00:00:00.000Z\",\"vuln_type |
||
255 | \":\"DOS\",\"references\":{\"url\":[\"https://baraktawily.blogspot. |
||
256 | fr/2018/02/how-to-dos-29-of-world-wide-websites.html\",\"https://gi |
||
257 | thub.com/quitten/doser.py\",\"https://thehackernews.com/2018/02/wor |
||
258 | dpress-dos-exploit.html\"],\"cve\":[\"2018-6389\"]},\"fixed_in\": " |
||
259 | 1.0"}]}}`, |
||
260 | in2: WpStatus{Name: "twentyfifteen", Status: "inactive", Update: "available", Version: "1.1"}, |
||
261 | expected: []models.VulnInfo{}, |
||
262 | }, |
||
263 | { |
||
264 | in1: `{\"4.9.4\":{\"release_date\":\"2018-02-06\",\"changelog_url\" |
||
265 | :\"https://codex.wordpress.org/Version_4.9.4\",\"status\":\"insecur |
||
266 | e\",\"vulnerabilities\":[{\"id\":9021,\"title\":\"WordPress <= 4.9. |
||
267 | 4 - Application Denial of Service (DoS) (unpatched)\",\"created_at\ |
||
268 | ":\"2018-02-05T16:50:40.000Z\",\"updated_at\":\"2018-08-29T19:13:04 |
||
269 | .000Z\",\"published_date\":\"2018-02-05T00:00:00.000Z\",\"vuln_type |
||
270 | \":\"DOS\",\"references\":{\"url\":[\"https://baraktawily.blogspot. |
||
271 | fr/2018/02/how-to-dos-29-of-world-wide-websites.html\",\"https://gi |
||
272 | thub.com/quitten/doser.py\",\"https://thehackernews.com/2018/02/wor |
||
273 | dpress-dos-exploit.html\"],\"cve\":[\"2018-6389\"]},\"fixed_in\": " |
||
274 | 1.2"}]}}`, |
||
275 | in2: WpStatus{Name: "twentyfifteen", Status: "inactive", Update: "available", Version: "1.1"}, |
||
276 | expected: []models.VulnInfo{ |
||
277 | { |
||
278 | CveID: "CVE-2018-6389", |
||
279 | Confidences: models.Confidences{}, |
||
280 | AffectedPackages: models.PackageStatuses{ |
||
281 | models.PackageStatus{ |
||
282 | Name: "", |
||
283 | NotFixedYet: false, |
||
284 | FixState: "", |
||
285 | }, |
||
286 | }, |
||
287 | DistroAdvisories: []models.DistroAdvisory{}, |
||
288 | CpeURIs: []string{}, |
||
289 | CveContents: models.NewCveContents( |
||
290 | models.CveContent{ |
||
291 | Type: "", |
||
292 | CveID: "CVE-2018-6389", |
||
293 | Title: "WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)", |
||
294 | Summary: "", |
||
295 | Cvss2Score: 0.000000, |
||
296 | Cvss2Vector: "", |
||
297 | Cvss2Severity: "", |
||
298 | Cvss3Score: 0.000000, |
||
299 | Cvss3Vector: "", |
||
300 | Cvss3Severity: "", |
||
301 | SourceLink: "", |
||
302 | Cpes: []models.Cpe{}, |
||
303 | References: models.References{}, |
||
304 | CweIDs: []string{}, |
||
305 | Published: time.Time{}, |
||
306 | LastModified: time.Time{}, |
||
307 | Mitigation: "", |
||
308 | Optional: map[string]string{}, |
||
309 | }, |
||
310 | ), |
||
311 | Exploits: []models.Exploit{}, |
||
312 | AlertDict: models.AlertDict{ |
||
313 | Ja: []alert.Alert{}, |
||
314 | En: []alert.Alert{}, |
||
315 | }, |
||
316 | }, |
||
317 | }, |
||
318 | }, |
||
319 | } |
||
320 | for _, test := range tests { |
||
321 | actual, _ := contentConvertVinfos(test.in1, test.in2) |
||
322 | if reflect.ValueOf(test.expected).Pointer() == reflect.ValueOf(actual).Pointer() { |
||
323 | t.Errorf("expected %v, actual %v", test.expected, actual) |
||
324 | } |
||
395 |