1
+ var expect = require ( 'chai' ) . expect ;
2
+ var automationAcctPublicAccess = require ( './automationAcctPublicAccess.js' ) ;
3
+
4
+ const automationAccounts = [
5
+ {
6
+ "id" : "/subscriptions/12345/resourceGroups/DefaultResourceGroup-EUS/providers/Microsoft.Automation/automationAccounts/Automate-12345-EUS2" ,
7
+ "location" : "EastUS2" ,
8
+ "name" : "Automate-12345-EUS2" ,
9
+ "type" : "Microsoft.Automation/AutomationAccounts" ,
10
+ "tags" : { } ,
11
+ "creationTime" : "2023-10-27T07:27:02.76+00:00" ,
12
+ "lastModifiedTime" : "2023-10-27T07:27:02.76+00:00" ,
13
+ "identity" : {
14
+ "type" : "systemassigned,userassigned" ,
15
+ "principalId" : "dc03d47d-e6df-491f-aebe-50a93412a890" ,
16
+ "tenantId" : "d207c7bd-fcb1-4dd3-855a-cfd2f9b651e8" ,
17
+ "userAssignedIdentities" : {
18
+ "/subscriptions/12345/resourcegroups/meerab-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/testmeerab" : {
19
+ "PrincipalId" : "123455" ,
20
+ "ClientId" : "1234554"
21
+ }
22
+ }
23
+ } ,
24
+ "publicNetworkAccess" : false ,
25
+
26
+ } ,
27
+ {
28
+ "id" : "/subscriptions/12345/resourceGroups/DefaultResourceGroup-CUS/providers/Microsoft.Automation/automationAccounts/Automate-12345-CUS" ,
29
+ "location" : "centralus" ,
30
+ "name" : "Automate-12345-CUS" ,
31
+ "type" : "Microsoft.Automation/AutomationAccounts" ,
32
+ "tags" : { } ,
33
+ "publicNetworkAccess" : true ,
34
+ }
35
+ ] ;
36
+
37
+ const createCache = ( automationAccounts , err ) => {
38
+ return {
39
+ automationAccounts : {
40
+ list : {
41
+ 'eastus' : {
42
+ data : automationAccounts ,
43
+ err : err
44
+ }
45
+ }
46
+ }
47
+ }
48
+ } ;
49
+
50
+ describe ( 'automationAcctPublicAccess' , function ( ) {
51
+ describe ( 'run' , function ( ) {
52
+
53
+ it ( 'should give pass result if No existing automation accounts found' , function ( done ) {
54
+ const cache = createCache ( [ ] ) ;
55
+ automationAcctPublicAccess . run ( cache , { } , ( err , results ) => {
56
+ expect ( results . length ) . to . equal ( 1 ) ;
57
+ expect ( results [ 0 ] . status ) . to . equal ( 0 ) ;
58
+ expect ( results [ 0 ] . message ) . to . include ( 'No existing Automation accounts found' ) ;
59
+ expect ( results [ 0 ] . region ) . to . equal ( 'eastus' ) ;
60
+ done ( ) ;
61
+ } ) ;
62
+ } ) ;
63
+
64
+ it ( 'should give unknown result if Unable to query automation accounts:' , function ( done ) {
65
+ const cache = createCache ( null , 'Error' ) ;
66
+ automationAcctPublicAccess . run ( cache , { } , ( err , results ) => {
67
+ expect ( results . length ) . to . equal ( 1 ) ;
68
+ expect ( results [ 0 ] . status ) . to . equal ( 3 ) ;
69
+ expect ( results [ 0 ] . message ) . to . include ( 'Unable to query Automation accounts:' ) ;
70
+ expect ( results [ 0 ] . region ) . to . equal ( 'eastus' ) ;
71
+ done ( ) ;
72
+ } ) ;
73
+ } ) ;
74
+
75
+ it ( 'should give passing result if automation account has public network access disabled' , function ( done ) {
76
+ const cache = createCache ( [ automationAccounts [ 0 ] ] ) ;
77
+ automationAcctPublicAccess . run ( cache , { } , ( err , results ) => {
78
+ expect ( results . length ) . to . equal ( 1 ) ;
79
+ expect ( results [ 0 ] . status ) . to . equal ( 0 ) ;
80
+ expect ( results [ 0 ] . message ) . to . include ( 'Automation account has public network access disabled' ) ;
81
+ expect ( results [ 0 ] . region ) . to . equal ( 'eastus' ) ;
82
+ done ( ) ;
83
+ } ) ;
84
+ } ) ;
85
+
86
+ it ( 'should give failing result if automation account does not have public network access disabled' , function ( done ) {
87
+ const cache = createCache ( [ automationAccounts [ 1 ] ] ) ;
88
+ automationAcctPublicAccess . run ( cache , { } , ( err , results ) => {
89
+ expect ( results . length ) . to . equal ( 1 ) ;
90
+ expect ( results [ 0 ] . status ) . to . equal ( 2 ) ;
91
+ expect ( results [ 0 ] . message ) . to . include ( 'Automation account does not have public network access disabled' ) ;
92
+ expect ( results [ 0 ] . region ) . to . equal ( 'eastus' ) ;
93
+ done ( ) ;
94
+ } ) ;
95
+ } ) ;
96
+ } ) ;
97
+ } ) ;
0 commit comments