-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBloodHound.OpenGraph.Model.Tests.ps1
More file actions
62 lines (51 loc) · 2.43 KB
/
BloodHound.OpenGraph.Model.Tests.ps1
File metadata and controls
62 lines (51 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<#
.SYNOPSIS
BloodHound OpenGraph Data Model Tests
.DESCRIPTION
Pester tests for the classes in the BloodHound OpenGraph Data Model
#>
#Requires -Version 5.1
#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.0' }
# Import the BloodHound OpenGraph data model
using module '.\BloodHound.OpenGraph.Model.psm1'
# Show errors for uninitialized variables, etc.
Set-StrictMode -Version Latest
Describe 'BloodHound OpenGraph Data Model' {
Context 'Basics' {
It 'requires the tenant ID to be set' {
{ [AZAuthenticationPolicy]::new() } | Should -Throw
}
It 'supports OpenGraph metadata' {
[string] $sourceKind = 'Test'
[BloodHoundOpenGraph] $openGraph = [BloodHoundOpenGraph]::new($sourceKind)
$openGraph.metadata.source_kind | Should -Be $sourceKind
}
It 'supports adding nodes' {
[BloodHoundOpenGraph] $openGraph = [BloodHoundOpenGraph]::new('Test')
[guid] $tenantId = [guid]::NewGuid()
[AZAuthenticationPolicy] $authenticationPolicy = [AZAuthenticationPolicy]::new($tenantId)
$openGraph.AddNode($authenticationPolicy)
$openGraph.graph.nodes.Count | Should -Be 1
$openGraph.graph.nodes[0].id | Should -Be "AZAuthenticationPolicy@$tenantId"
}
It 'supports adding edges' {
[BloodHoundOpenGraph] $openGraph = [BloodHoundOpenGraph]::new('Test')
[guid] $tenantId = [guid]::NewGuid()
[AZAuthenticationPolicy] $authenticationPolicy = [AZAuthenticationPolicy]::new($tenantId)
$openGraph.AddNode($authenticationPolicy)
[AZGroup] $group = [AZGroup]::new([guid]::NewGuid(), $tenantId)
$openGraph.AddNode($group)
$openGraph.AddEdge([AZTapInclude]::new($authenticationPolicy, $group))
$openGraph.graph.edges.Count | Should -Be 1
$openGraph.graph.edges[0].start.value | Should -Be $group.id
$openGraph.graph.edges[0].end.value | Should -Be "AZAuthenticationPolicy@$tenantId"
$openGraph.graph.edges[0].kind | Should -Be 'AZTapInclude'
}
}
Context 'JSON Export' {
It 'empty graph can be exported' {
[BloodHoundOpenGraph] $openGraph = [BloodHoundOpenGraph]::new('Test')
$openGraph.ToJson($true) | Should -Be '{"metadata":{"source_kind":"Test"},"graph":{"nodes":[],"edges":[]}}'
}
}
}