|
| 1 | +# SPDX-License-Identifier: Proprietary |
| 2 | +# |
| 3 | +# ASRFacet-Rb: Attack Surface Reconnaissance Framework |
| 4 | +# Copyright (c) 2026 voltsparx |
| 5 | +# |
| 6 | +# Author: voltsparx |
| 7 | +# Repository: https://github.com/voltsparx/ASRFacet-Rb |
| 8 | +# Contact: voltsparx@gmail.com |
| 9 | +# License: See LICENSE file in the project root |
| 10 | +# |
| 11 | +# This file is part of ASRFacet-Rb and is subject to the terms |
| 12 | +# and conditions defined in the LICENSE file. |
| 13 | + |
| 14 | +require "spec_helper" |
| 15 | +require "stringio" |
| 16 | +require "tmpdir" |
| 17 | + |
| 18 | +RSpec.describe ASRFacet::UI::CLI do |
| 19 | + def capture_stdout |
| 20 | + original = $stdout |
| 21 | + buffer = StringIO.new |
| 22 | + $stdout = buffer |
| 23 | + yield |
| 24 | + buffer.string |
| 25 | + ensure |
| 26 | + $stdout = original |
| 27 | + end |
| 28 | + |
| 29 | + def wire_workspace_root(dir) |
| 30 | + manager = ASRFacet::Intelligence::SessionManager.new(root: dir) |
| 31 | + allow(ASRFacet::Intelligence::SessionManager).to receive(:new).and_return(manager) |
| 32 | + allow(ASRFacet::Intelligence::AssetGraph).to receive(:new).and_wrap_original do |method, target, **kwargs| |
| 33 | + method.call(target, **kwargs.merge(root: dir)) |
| 34 | + end |
| 35 | + manager |
| 36 | + end |
| 37 | + |
| 38 | + it "lists, shows, exports, and deletes persisted workspaces through the CLI" do |
| 39 | + Dir.mktmpdir do |dir| |
| 40 | + manager = wire_workspace_root(dir) |
| 41 | + manager.create("lab.example.com") |
| 42 | + build_intelligence_graph(root: dir) |
| 43 | + |
| 44 | + list_output = capture_stdout { described_class.start(["workspace", "list"]) } |
| 45 | + show_output = capture_stdout { described_class.start(["workspace", "show", "lab.example.com"]) } |
| 46 | + export_output = capture_stdout { described_class.start(["workspace", "export", "lab.example.com", "--format", "csv"]) } |
| 47 | + |
| 48 | + expect(list_output).to include("lab.example.com") |
| 49 | + expect(JSON.parse(show_output)).to include("target" => "lab.example.com") |
| 50 | + |
| 51 | + export_path = export_output.strip |
| 52 | + expect(export_path).to end_with(".csv") |
| 53 | + expect(File).to exist(export_path) |
| 54 | + |
| 55 | + delete_output = capture_stdout { described_class.start(["workspace", "delete", "lab.example.com"]) } |
| 56 | + expect(delete_output).to include("Workspace deleted") |
| 57 | + expect(capture_stdout { described_class.start(["workspace", "show", "lab.example.com"]) }).to include("Workspace not found") |
| 58 | + end |
| 59 | + end |
| 60 | + |
| 61 | + it "tracks diffs, renders graph exports, and lists stored subdomains from a workspace" do |
| 62 | + Dir.mktmpdir do |dir| |
| 63 | + manager = wire_workspace_root(dir) |
| 64 | + manager.create("lab.example.com") |
| 65 | + build_intelligence_graph("intelligence_graph_previous", root: dir) |
| 66 | + manager.export("lab.example.com", format: "json") |
| 67 | + build_intelligence_graph(root: dir) |
| 68 | + |
| 69 | + track_output = capture_stdout { described_class.start(["track", "lab.example.com", "--since", "2099-01-01"]) } |
| 70 | + viz_output = capture_stdout { described_class.start(["viz", "lab.example.com", "--format", "mermaid"]) } |
| 71 | + subs_output = capture_stdout { described_class.start(["subs", "lab.example.com"]) } |
| 72 | + |
| 73 | + diff = JSON.parse(track_output) |
| 74 | + expect(diff.dig("summary", "added")).to be > 0 |
| 75 | + expect(viz_output).to include("graph LR") |
| 76 | + expect(subs_output.lines.map(&:strip)).to eq(%w[api.lab.example.com app.lab.example.com]) |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + it "reports invalid track dates as parse errors without crashing" do |
| 81 | + Dir.mktmpdir do |dir| |
| 82 | + manager = wire_workspace_root(dir) |
| 83 | + manager.create("lab.example.com") |
| 84 | + build_intelligence_graph(root: dir) |
| 85 | + |
| 86 | + output = capture_stdout { described_class.start(["track", "lab.example.com", "--since", "not-a-date"]) } |
| 87 | + |
| 88 | + expect(output).to include("Invalid --since value") |
| 89 | + end |
| 90 | + end |
| 91 | +end |
0 commit comments