@@ -55,7 +55,7 @@ describe(commands.FILE_SHARINGLINK_LIST, () => {
55
55
"grantedToIdentitiesV2" : [ ] ,
56
56
"grantedToIdentities" : [ ] ,
57
57
"link" : {
58
- "scope" : "anonymous " ,
58
+ "scope" : "users " ,
59
59
"type" : "view" ,
60
60
"webUrl" : "https://contoso.sharepoint.com/:b:/s/pnpcoresdktestgroup/EY50lub3559MtRKfj2hrZqoBsS_o5pIcCyNIL3D_vEyG5Q" ,
61
61
"preventsDownload" : true
@@ -70,7 +70,7 @@ describe(commands.FILE_SHARINGLINK_LIST, () => {
70
70
"grantedToIdentitiesV2" : [ ] ,
71
71
"grantedToIdentities" : [ ] ,
72
72
"link" : {
73
- "scope" : "anonymous " ,
73
+ "scope" : "organization " ,
74
74
"type" : "edit" ,
75
75
"webUrl" : "https://contoso.sharepoint.com/:b:/s/pnpcoresdktestgroup/EY50lub3559MtRKfj2hrZqoBDyAMq6f9C2eqWwFsbei6nA" ,
76
76
"preventsDownload" : false
@@ -83,17 +83,8 @@ describe(commands.FILE_SHARINGLINK_LIST, () => {
83
83
{
84
84
"id" : "2a021f54-90a2-4016-b3b3-5f34d2e7d932" ,
85
85
"roles" : "read" ,
86
- "link" : "https://contoso.sharepoint.com/:b:/s/pnpcoresdktestgroup/EY50lub3559MtRKfj2hrZqoBWnHOpGIcgi4gzw9XiWYJ-A"
87
- } ,
88
- {
89
- "id" : "a47e5387-8868-497c-bb00-115c66c60390" ,
90
- "roles" : "read" ,
91
- "link" : "https://contoso.sharepoint.com/:b:/s/pnpcoresdktestgroup/EY50lub3559MtRKfj2hrZqoBsS_o5pIcCyNIL3D_vEyG5Q"
92
- } ,
93
- {
94
- "id" : "8bf1ca81-a63f-4796-9af5-d86ded8ce5a7" ,
95
- "roles" : "write" ,
96
- "link" : "https://contoso.sharepoint.com/:b:/s/pnpcoresdktestgroup/EY50lub3559MtRKfj2hrZqoBDyAMq6f9C2eqWwFsbei6nA"
86
+ "link" : "https://contoso.sharepoint.com/:b:/s/pnpcoresdktestgroup/EY50lub3559MtRKfj2hrZqoBWnHOpGIcgi4gzw9XiWYJ-A" ,
87
+ "scope" : "anonymous"
97
88
}
98
89
] ;
99
90
@@ -106,6 +97,15 @@ describe(commands.FILE_SHARINGLINK_LIST, () => {
106
97
} ) ;
107
98
} ;
108
99
100
+ const stubOdataScopeResponse : any = ( scope : any = null , graphResponse : any = null ) => {
101
+ return sinon . stub ( odata , 'getAllItems' ) . callsFake ( async ( url : string ) => {
102
+ if ( url === `https://graph.microsoft.com/v1.0/sites/${ fileDetailsResponse . SiteId } /drives/${ fileDetailsResponse . VroomDriveID } /items/${ fileDetailsResponse . VroomItemID } /permissions?$filter=Link ne null and Link/Scope eq '${ scope } '` ) {
103
+ return graphResponse . value . filter ( ( x : any ) => x . link . scope === scope ) ;
104
+ }
105
+ throw 'Invalid request' ;
106
+ } ) ;
107
+ } ;
108
+
109
109
before ( ( ) => {
110
110
sinon . stub ( auth , 'restoreAuth' ) . callsFake ( ( ) => Promise . resolve ( ) ) ;
111
111
sinon . stub ( telemetry , 'trackEvent' ) . callsFake ( ( ) => { } ) ;
@@ -182,8 +182,54 @@ describe(commands.FILE_SHARINGLINK_LIST, () => {
182
182
assert ( loggerLogSpy . calledWith ( graphResponse . value ) ) ;
183
183
} ) ;
184
184
185
+ it ( 'retrieves sharing links from file specified by url and scope anonymous' , async ( ) => {
186
+ const scope = 'anonymous' ;
187
+ stubOdataScopeResponse ( scope , graphResponse ) ;
188
+ sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
189
+ if ( opts . url === `${ webUrl } /_api/web/GetFileByServerRelativePath(decodedUrl='${ formatting . encodeQueryParameter ( fileUrl ) } ')?$select=SiteId,VroomItemId,VroomDriveId` ) {
190
+ return fileDetailsResponse ;
191
+ }
192
+
193
+ throw 'Invalid request' ;
194
+ } ) ;
195
+
196
+ await command . action ( logger , { options : { webUrl : webUrl , fileUrl : fileUrl , scope : scope , output : 'json' , verbose : true } } as any ) ;
197
+ assert ( loggerLogSpy . calledWith ( graphResponse . value . filter ( x => x . link . scope === scope ) ) ) ;
198
+ } ) ;
199
+
200
+ it ( 'retrieves sharing links from file specified by url and scope users' , async ( ) => {
201
+ const scope = 'users' ;
202
+ stubOdataScopeResponse ( scope , graphResponse ) ;
203
+ sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
204
+ if ( opts . url === `${ webUrl } /_api/web/GetFileByServerRelativePath(decodedUrl='${ formatting . encodeQueryParameter ( fileUrl ) } ')?$select=SiteId,VroomItemId,VroomDriveId` ) {
205
+ return fileDetailsResponse ;
206
+ }
207
+
208
+ throw 'Invalid request' ;
209
+ } ) ;
210
+
211
+ await command . action ( logger , { options : { webUrl : webUrl , fileUrl : fileUrl , scope : scope , output : 'json' , verbose : true } } as any ) ;
212
+ assert ( loggerLogSpy . calledWith ( graphResponse . value . filter ( x => x . link . scope === scope ) ) ) ;
213
+ } ) ;
214
+
215
+ it ( 'retrieves sharing links from file specified by url and scope organization' , async ( ) => {
216
+ const scope = 'organization' ;
217
+ stubOdataScopeResponse ( scope , graphResponse ) ;
218
+ sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
219
+ if ( opts . url === `${ webUrl } /_api/web/GetFileByServerRelativePath(decodedUrl='${ formatting . encodeQueryParameter ( fileUrl ) } ')?$select=SiteId,VroomItemId,VroomDriveId` ) {
220
+ return fileDetailsResponse ;
221
+ }
222
+
223
+ throw 'Invalid request' ;
224
+ } ) ;
225
+
226
+ await command . action ( logger , { options : { webUrl : webUrl , fileUrl : fileUrl , scope : scope , output : 'json' , verbose : true } } as any ) ;
227
+ assert ( loggerLogSpy . calledWith ( graphResponse . value . filter ( x => x . link . scope === scope ) ) ) ;
228
+ } ) ;
229
+
185
230
it ( 'retrieves sharing links from file specified by url with output text' , async ( ) => {
186
- stubOdataResponse ( graphResponse ) ;
231
+ const scope = 'anonymous' ;
232
+ stubOdataScopeResponse ( scope , graphResponse ) ;
187
233
sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
188
234
if ( opts . url === `${ webUrl } /_api/web/GetFileByServerRelativePath(decodedUrl='${ formatting . encodeQueryParameter ( fileUrl ) } ')?$select=SiteId,VroomItemId,VroomDriveId` ) {
189
235
return fileDetailsResponse ;
@@ -192,7 +238,7 @@ describe(commands.FILE_SHARINGLINK_LIST, () => {
192
238
throw 'Invalid request' ;
193
239
} ) ;
194
240
195
- await command . action ( logger , { options : { webUrl : webUrl , fileUrl : fileUrl , output : 'text' , verbose : true } } as any ) ;
241
+ await command . action ( logger , { options : { webUrl : webUrl , fileUrl : fileUrl , scope : scope , output : 'text' , verbose : true } } as any ) ;
196
242
assert ( loggerLogSpy . calledWith ( graphResponseText ) ) ;
197
243
} ) ;
198
244
@@ -219,6 +265,11 @@ describe(commands.FILE_SHARINGLINK_LIST, () => {
219
265
assert . notStrictEqual ( actual , true ) ;
220
266
} ) ;
221
267
268
+ it ( 'fails validation if invalid scope specified' , async ( ) => {
269
+ const actual = await command . validate ( { options : { webUrl : 'https://contoso.sharepoint.com' , fileId : fileId , scope : 'invalid scope' } } , commandInfo ) ;
270
+ assert . notStrictEqual ( actual , true ) ;
271
+ } ) ;
272
+
222
273
it ( 'passes validation if options are valid' , async ( ) => {
223
274
const actual = await command . validate ( { options : { webUrl : 'https://contoso.sharepoint.com' , fileId : fileId } } , commandInfo ) ;
224
275
assert . strictEqual ( actual , true ) ;
0 commit comments