@@ -11,12 +11,12 @@ import { session } from '../../../utils/session.js';
11
11
import { sinonUtil } from '../../../utils/sinonUtil.js' ;
12
12
import commands from '../commands.js' ;
13
13
import command from './app-get.js' ;
14
+ import { entraApp } from '../../../utils/entraApp.js' ;
14
15
15
16
describe ( commands . GET , ( ) => {
16
17
let log : string [ ] ;
17
18
let logger : Logger ;
18
19
let loggerLogSpy : sinon . SinonSpy ;
19
- let loggerLogToStderrSpy : sinon . SinonSpy ;
20
20
21
21
before ( ( ) => {
22
22
sinon . stub ( auth , 'restoreAuth' ) . resolves ( ) ;
@@ -49,12 +49,12 @@ describe(commands.GET, () => {
49
49
}
50
50
} ;
51
51
loggerLogSpy = sinon . spy ( logger , 'log' ) ;
52
- loggerLogToStderrSpy = sinon . spy ( logger , 'logToStderr' ) ;
53
52
} ) ;
54
53
55
54
afterEach ( ( ) => {
56
55
sinonUtil . restore ( [
57
- request . get
56
+ request . get ,
57
+ entraApp . getAppRegistrationByAppId
58
58
] ) ;
59
59
} ) ;
60
60
@@ -72,59 +72,30 @@ describe(commands.GET, () => {
72
72
} ) ;
73
73
74
74
it ( 'handles error when the app specified with the appId not found' , async ( ) => {
75
- sinon . stub ( request , 'get' ) . callsFake ( async opts => {
76
- if ( opts . url === `https://graph.microsoft.com/v1.0/myorganization/applications?$filter=appId eq '9b1b1e42-794b-4c71-93ac-5ed92488b67f'&$select=id` ) {
77
- return { value : [ ] } ;
78
- }
79
-
80
- throw `Invalid request ${ JSON . stringify ( opts ) } ` ;
81
- } ) ;
82
-
83
- await assert . rejects ( command . action ( logger , {
84
- options : {
85
- appId : '9b1b1e42-794b-4c71-93ac-5ed92488b67f'
86
- }
87
- } ) , new CommandError ( `No Microsoft Entra application registration with ID 9b1b1e42-794b-4c71-93ac-5ed92488b67f found` ) ) ;
88
- } ) ;
89
-
90
- it ( 'handles error when retrieving information about app through appId failed' , async ( ) => {
91
- sinon . stub ( request , 'get' ) . rejects ( new Error ( 'An error has occurred' ) ) ;
75
+ const error = `App with appId '9b1b1e42-794b-4c71-93ac-5ed92488b67f' not found in Microsoft Entra ID` ;
76
+ sinon . stub ( entraApp , 'getAppRegistrationByAppId' ) . rejects ( new Error ( error ) ) ;
92
77
93
78
await assert . rejects ( command . action ( logger , {
94
79
options : {
95
80
appId : '9b1b1e42-794b-4c71-93ac-5ed92488b67f'
96
81
}
97
- } ) , new CommandError ( `An error has occurred ` ) ) ;
82
+ } ) , new CommandError ( `App with appId '9b1b1e42-794b-4c71-93ac-5ed92488b67f' not found in Microsoft Entra ID ` ) ) ;
98
83
} ) ;
99
84
100
85
it ( `gets an Microsoft Entra app registration by its app (client) ID.` , async ( ) => {
101
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
102
- if ( opts . url === `https://graph.microsoft.com/v1.0/myorganization/applications?$filter=appId eq '9b1b1e42-794b-4c71-93ac-5ed92488b67f'&$select=id` ) {
103
- return {
104
- value : [
105
- {
106
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
107
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
108
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
109
- "displayName" : "My App" ,
110
- "description" : null
111
- }
112
- ]
113
- } ;
114
- }
115
-
116
- if ( ( opts . url as string ) . indexOf ( '/v1.0/myorganization/applications/' ) > - 1 ) {
117
- return {
86
+ const appResponse = {
87
+ value : [
88
+ {
118
89
"id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
119
90
"appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
120
91
"createdDateTime" : "2019-10-29T17:46:55Z" ,
121
92
"displayName" : "My App" ,
122
93
"description" : null
123
- } ;
124
- }
94
+ }
95
+ ]
96
+ } ;
125
97
126
- throw 'Invalid request' ;
127
- } ) ;
98
+ sinon . stub ( entraApp , 'getAppRegistrationByAppId' ) . resolves ( appResponse . value [ 0 ] ) ;
128
99
129
100
await command . action ( logger , {
130
101
options : {
@@ -136,43 +107,4 @@ describe(commands.GET, () => {
136
107
assert . strictEqual ( call . args [ 0 ] . appId , '9b1b1e42-794b-4c71-93ac-5ed92488b67f' ) ;
137
108
assert . strictEqual ( call . args [ 0 ] . displayName , 'My App' ) ;
138
109
} ) ;
139
-
140
- it ( `shows underlying debug information in debug mode` , async ( ) => {
141
- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
142
- if ( opts . url === `https://graph.microsoft.com/v1.0/myorganization/applications?$filter=appId eq '9b1b1e42-794b-4c71-93ac-5ed92488b67f'&$select=id` ) {
143
- return {
144
- value : [
145
- {
146
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
147
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
148
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
149
- "displayName" : "My App" ,
150
- "description" : null
151
- }
152
- ]
153
- } ;
154
- }
155
-
156
- if ( ( opts . url as string ) . indexOf ( '/v1.0/myorganization/applications/' ) > - 1 ) {
157
- return {
158
- "id" : "340a4aa3-1af6-43ac-87d8-189819003952" ,
159
- "appId" : "9b1b1e42-794b-4c71-93ac-5ed92488b67f" ,
160
- "createdDateTime" : "2019-10-29T17:46:55Z" ,
161
- "displayName" : "My App" ,
162
- "description" : null
163
- } ;
164
- }
165
-
166
- throw 'Invalid request' ;
167
- } ) ;
168
-
169
- await command . action ( logger , {
170
- options : {
171
- appId : '9b1b1e42-794b-4c71-93ac-5ed92488b67f' ,
172
- debug : true
173
- }
174
- } ) ;
175
- const call : sinon . SinonSpyCall = loggerLogToStderrSpy . firstCall ;
176
- assert ( call . args [ 0 ] . includes ( 'Executing command entra app get with options' ) ) ;
177
- } ) ;
178
110
} ) ;
0 commit comments