Skip to content

Commit d9b914a

Browse files
committed
feat: tagged threats in srtm in-scope
1 parent 39c0722 commit d9b914a

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

valentine/lib/valentine_web/live/workspace_live/srtm/index.ex

+11-7
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ defmodule ValentineWeb.WorkspaceLive.SRTM.Index do
6060
|> assign(:page_title, gettext("Security Requirements Traceability Matrix"))
6161
end
6262

63-
defp allocated_controls(controls, assumed, mitigated) do
64-
assumed_ids = Map.keys(assumed)
65-
mitigated_ids = Map.keys(mitigated)
63+
defp allocated_controls(controls, assumed, mitigated, threats) do
64+
out_of_scope_ids = Map.keys(assumed)
65+
in_scope_ids = (Map.keys(mitigated) ++ Map.keys(threats)) |> Enum.uniq()
6666

6767
initial_acc = %{
6868
not_allocated: %{},
@@ -72,18 +72,18 @@ defmodule ValentineWeb.WorkspaceLive.SRTM.Index do
7272

7373
Enum.reduce(controls, initial_acc, fn control, acc ->
7474
cond do
75-
control.nist_id in assumed_ids ->
75+
control.nist_id in out_of_scope_ids ->
7676
put_in(
7777
acc,
7878
[:out_of_scope, control.nist_id],
7979
[{control, assumed[control.nist_id]}]
8080
)
8181

82-
control.nist_id in mitigated_ids ->
82+
control.nist_id in in_scope_ids ->
8383
put_in(
8484
acc,
8585
[:in_scope, control.nist_id],
86-
[{control, mitigated[control.nist_id]}]
86+
[{control, (mitigated[control.nist_id] || []) ++ (threats[control.nist_id] || [])}]
8787
)
8888

8989
true ->
@@ -124,10 +124,14 @@ defmodule ValentineWeb.WorkspaceLive.SRTM.Index do
124124
)
125125
end
126126

127+
defp item_content(item = %Composer.Threat{}), do: Composer.Threat.show_statement(item)
128+
defp item_content(item), do: item.content
129+
127130
defp map_controls(controls, workspace) do
128131
assumed_controls = get_tagged_controls(workspace.assumptions)
129132
mitigated_controls = get_tagged_controls(workspace.mitigations)
130-
allocated_controls(controls, assumed_controls, mitigated_controls)
133+
threat_controls = get_tagged_controls(workspace.threats)
134+
allocated_controls(controls, assumed_controls, mitigated_controls, threat_controls)
131135
end
132136

133137
defp calculate_percentage(controls, scope) do

valentine/lib/valentine_web/live/workspace_live/srtm/index.html.heex

+7-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,14 @@
132132
<% :out_of_scope -> %>
133133
{gettext("Covered by assumption")}:
134134
<% :in_scope -> %>
135-
{gettext("Mitigated by")}:
135+
<%= case item do %>
136+
<% _ = %Valentine.Composer.Threat{} -> %>
137+
{gettext("Threatened by")}:
138+
<% _ -> %>
139+
{gettext("Mitigated by")}:
140+
<% end %>
136141
<% end %>
137-
{item.content}
142+
{item_content(item)}
138143
</summary>
139144
<%= if item.comments do %>
140145
<div class="mt-1 pl-4">

valentine/test/valentine_web/live/workspace/srtm/index_test.exs

+22
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,28 @@ defmodule ValentineWeb.WorkspaceLive.SRTM.IndexTest do
9696
assert assigned_mitigation.id == mitigation.id
9797
assert socket.assigns.workspace.id == workspace.id
9898
end
99+
100+
test "mounts threats into the correct category", %{
101+
workspace: workspace,
102+
socket: socket
103+
} do
104+
threat =
105+
threat_fixture(%{
106+
tags: ["AC-1"],
107+
workspace_id: workspace.id
108+
})
109+
110+
{:ok, socket} =
111+
ValentineWeb.WorkspaceLive.SRTM.Index.mount(
112+
%{"workspace_id" => workspace.id},
113+
nil,
114+
socket
115+
)
116+
117+
[{_, [assigned_threat]}] = socket.assigns.controls[:in_scope]["AC-1"]
118+
assert assigned_threat.id == threat.id
119+
assert socket.assigns.workspace.id == workspace.id
120+
end
99121
end
100122

101123
describe "handle_event/3" do

0 commit comments

Comments
 (0)