-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1766 Importing patterns now updates existing patterns
- Loading branch information
Showing
4 changed files
with
133 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,81 @@ class PatternCtrlTest extends PlaySpecification with TestAppBuilder { | |
contentAsJson(result).as[JsArray].value.size must beEqualTo(2) | ||
} | ||
|
||
"import & update a pattern" in testApp { app => | ||
// Get a pattern | ||
val request1 = FakeRequest("GET", "/api/v1/pattern/T123") | ||
.withHeaders("user" -> "[email protected]") | ||
|
||
val result1 = app[PatternCtrl].get("T123")(request1) | ||
status(result1) must beEqualTo(200).updateMessage(s => s"$s\n${contentAsString(result1)}") | ||
val result1Pattern = contentAsJson(result1).as[OutputPattern] | ||
|
||
TestPattern(result1Pattern) must_=== TestPattern( | ||
"T123", | ||
"testPattern1", | ||
Some("The testPattern 1"), | ||
Set("testTactic1", "testTactic2"), | ||
"http://test.pattern.url", | ||
"unit-test", | ||
None, | ||
None, | ||
revoked = false, | ||
Seq(), | ||
Seq(), | ||
None, | ||
Seq(), | ||
Seq(), | ||
remoteSupport = true, | ||
Seq(), | ||
Some("1.0") | ||
) | ||
|
||
// Update a pattern | ||
val request2 = FakeRequest("POST", "/api/v1/pattern/import/attack") | ||
.withHeaders("user" -> "[email protected]") | ||
.withBody( | ||
AnyContentAsMultipartFormData( | ||
MultipartFormData( | ||
dataParts = Map.empty, | ||
files = | ||
Seq(FilePart("file", "patternsUpdate.json", Option("application/json"), FakeTemporaryFile.fromResource("/patternsUpdate.json"))), | ||
badParts = Seq() | ||
) | ||
) | ||
) | ||
|
||
val result2 = app[PatternCtrl].importMitre(request2) | ||
status(result2) must beEqualTo(201).updateMessage(s => s"$s\n${contentAsString(result2)}") | ||
|
||
// Check for updates | ||
val request3 = FakeRequest("GET", "/api/v1/pattern/T123") | ||
.withHeaders("user" -> "[email protected]") | ||
|
||
val result3 = app[PatternCtrl].get("T123")(request3) | ||
status(result3) must beEqualTo(200).updateMessage(s => s"$s\n${contentAsString(result3)}") | ||
val result3Pattern = contentAsJson(result3).as[OutputPattern] | ||
|
||
TestPattern(result3Pattern) must_=== TestPattern( | ||
"T123", | ||
"Updated testPattern1", | ||
None, | ||
Set(), | ||
"https://attack.mitre.org/techniques/T123", | ||
"attack-pattern", | ||
None, | ||
None, | ||
revoked = true, | ||
Seq(), | ||
Seq(), | ||
None, | ||
Seq(), | ||
Seq(), | ||
remoteSupport = false, | ||
Seq(), | ||
None | ||
) | ||
} | ||
|
||
"delete a pattern" in testApp { app => | ||
val request1 = FakeRequest("GET", "/api/v1/pattern/testPattern1") | ||
.withHeaders("user" -> "[email protected]") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"type": "bundle", | ||
"id": "bundle--ad5f3bce-004b-417e-899d-392f8591ab55", | ||
"spec_version": "2.0", | ||
"objects": [ | ||
{ | ||
"id": "testPattern1", | ||
"name": "Updated testPattern1", | ||
"external_references": [ | ||
{ | ||
"source_name": "mitre-attack", | ||
"external_id": "T123", | ||
"url": "https://attack.mitre.org/techniques/T123" | ||
} | ||
], | ||
"revoked": true, | ||
"type": "attack-pattern", | ||
"modified": "2020-01-24T14:14:05.452Z", | ||
"created": "2017-12-14T16:46:06.044Z" | ||
} | ||
] | ||
} |