Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix missing Owner/Initiator GCS #1369

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading