Skip to content

Commit

Permalink
fix missing Owner/Initiator GCS (#1369)
Browse files Browse the repository at this point in the history
  • Loading branch information
loremaps authored Dec 19, 2024
1 parent c6f3565 commit fd12add
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/internal/xml-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ export type ListMultipartResult = {
uploads: {
key: string
uploadId: UploadID
initiator: unknown
owner: unknown
initiator?: { id: string; displayName: string }
owner?: { id: string; displayName: string }
storageClass: unknown
initiated: Date
}[]
Expand Down Expand Up @@ -381,13 +381,19 @@ export function parseListMultipart(xml: string): ListMultipartResult {

if (xmlobj.Upload) {
toArray(xmlobj.Upload).forEach((upload) => {
const key = upload.Key
const uploadId = upload.UploadId
const initiator = { id: upload.Initiator.ID, displayName: upload.Initiator.DisplayName }
const owner = { id: upload.Owner.ID, displayName: upload.Owner.DisplayName }
const storageClass = upload.StorageClass
const initiated = new Date(upload.Initiated)
result.uploads.push({ key, uploadId, initiator, owner, storageClass, initiated })
const uploadItem: ListMultipartResult['uploads'][number] = {
key: upload.Key,
uploadId: upload.UploadId,
storageClass: upload.StorageClass,
initiated: new Date(upload.Initiated),
}
if (upload.Initiator) {
uploadItem.initiator = { id: upload.Initiator.ID, displayName: upload.Initiator.DisplayName }
}
if (upload.Owner) {
uploadItem.owner = { id: upload.Owner.ID, displayName: upload.Owner.DisplayName }
}
result.uploads.push(uploadItem)
})
}
return result
Expand Down
35 changes: 34 additions & 1 deletion tests/unit/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
partsRequired,
} from '../../src/internal/helper.ts'
import { joinHostPort } from '../../src/internal/join-host-port.ts'
import { parseListObjects } from '../../src/internal/xml-parser.ts'
import { parseListMultipart, parseListObjects } from '../../src/internal/xml-parser.ts'
import * as Minio from '../../src/minio.js'

const Package = { version: 'development' }
Expand Down Expand Up @@ -2304,6 +2304,39 @@ describe('xml-parser', () => {
})
})
})

describe('#listMultipart()', () => {
describe('should handle missing owner and initiator', () => {
// example response from GCS
const xml = `
<?xml version='1.0' encoding='UTF-8'?>
<ListMultipartUploadsResult
xmlns='http://s3.amazonaws.com/doc/2006-03-01/'>
<Bucket>some-bucket</Bucket>
<KeyMarker></KeyMarker>
<UploadIdMarker></UploadIdMarker>
<NextKeyMarker></NextKeyMarker>
<Prefix>some-file.pdf</Prefix>
<Delimiter>/</Delimiter>
<NextUploadIdMarker></NextUploadIdMarker>
<MaxUploads>1000</MaxUploads>
<IsTruncated>false</IsTruncated>
<Upload>
<Key>some-file.pdf</Key>
<UploadId>ABPnzm4aGoV3sjevTkVeaWV6lvBFtdjcZegTJg8MUfTue1t6lgRIy6_JEoM0km3CNE218x00</UploadId>
<StorageClass>STANDARD</StorageClass>
<Initiated>2024-12-17T08:16:52.396303Z</Initiated>
</Upload>
</ListMultipartUploadsResult>
`

it('should parse list incomplete', () => {
const { uploads } = parseListMultipart(xml)
assert.equal(uploads.length, 1)
assert.equal(uploads[0].key, 'some-file.pdf')
})
})
})
})

describe('join-host-port', () => {
Expand Down

0 comments on commit fd12add

Please sign in to comment.