expect(() => apiClientAuthorizationService.createCollectionSharingToken("foo")).toThrowError("UUID foo is not a collection");
});
- it('should make a create request with proper scopes', async () => {
+ it('should make a create request with proper scopes and no expiration date', async () => {
serverApi.post = jest.fn(() => Promise.resolve(
{ data: { uuid: 'zzzzz-4zz18-0123456789abcde' } }
));
}
);
});
+
+ it('should make a create request with proper scopes and expiration date', async () => {
+ serverApi.post = jest.fn(() => Promise.resolve(
+ { data: { uuid: 'zzzzz-4zz18-0123456789abcde' } }
+ ));
+ const uuid = 'zzzzz-4zz18-0123456789abcde'
+ const expDate = new Date(2022, 8, 28, 12, 0, 0);
+ await apiClientAuthorizationService.createCollectionSharingToken(uuid, expDate);
+ expect(serverApi.post).toHaveBeenCalledWith(
+ '/api_client_authorizations', {
+ scopes: [
+ `GET /arvados/v1/collections/${uuid}`,
+ `GET /arvados/v1/collections/${uuid}/`,
+ `GET /arvados/v1/keep_services/accessible`,
+ ],
+ expires_at: expDate.toUTCString()
+ }
+ );
+ });
});
describe('listCollectionSharingToken', () => {
super(serverApi, "api_client_authorizations", actions);
}
- createCollectionSharingToken(uuid: string): Promise<ApiClientAuthorization> {
+ createCollectionSharingToken(uuid: string, expDate: Date | undefined): Promise<ApiClientAuthorization> {
if (extractUuidObjectType(uuid) !== ResourceObjectType.COLLECTION) {
throw new Error(`UUID ${uuid} is not a collection`);
}
- return this.create({
+ const data = {
scopes: [
`GET /arvados/v1/collections/${uuid}`,
`GET /arvados/v1/collections/${uuid}/`,
`GET /arvados/v1/keep_services/accessible`,
]
- });
+ }
+ return expDate !== undefined
+ ? this.create({...data, expiresAt: expDate.toUTCString()})
+ : this.create(data);
}
listCollectionSharingTokens(uuid: string): Promise<ListResults<ApiClientAuthorization>> {
refresh: () => void;
}
-export const createSharingToken = async (dispatch: Dispatch, getState: () => RootState, { apiClientAuthorizationService }: ServiceRepository) => {
+export const createSharingToken = (expDate: Date | undefined) => async (dispatch: Dispatch, getState: () => RootState, { apiClientAuthorizationService }: ServiceRepository) => {
const dialog = getDialog<SharingDialogData>(getState().dialog, SHARING_DIALOG_NAME);
if (dialog) {
const resourceUuid = dialog.data.resourceUuid;
if (extractUuidObjectType(resourceUuid) === ResourceObjectType.COLLECTION) {
dispatch(progressIndicatorActions.START_WORKING(SHARING_DIALOG_NAME));
try {
- const sharingToken = await apiClientAuthorizationService.createCollectionSharingToken(resourceUuid);
+ const sharingToken = await apiClientAuthorizationService.createCollectionSharingToken(resourceUuid, expDate);
dispatch(resourcesActions.SET_RESOURCES([sharingToken]));
dispatch(snackbarActions.OPEN_SNACKBAR({
message: 'Sharing URL created',