mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-28 07:40:59 +00:00
Merge pull request #118 from overleaf/msm-fixed-object-key-templates
Fixed regular expression to insert/delete files not supporting templates API
This commit is contained in:
commit
b6b042e050
2 changed files with 22 additions and 2 deletions
|
@ -29,7 +29,7 @@ module.exports = {
|
|||
|
||||
async function insertFile(bucket, key, stream) {
|
||||
const convertedKey = KeyBuilder.getConvertedFolderKey(key)
|
||||
if (!convertedKey.match(/^[0-9a-f]{24}\/[0-9a-f]{24}/i)) {
|
||||
if (!convertedKey.match(/^[0-9a-f]{24}\/([0-9a-f]{24}|v\/[0-9]+\/[a-z]+)/i)) {
|
||||
throw new InvalidParametersError({
|
||||
message: 'key does not match validation regex',
|
||||
info: { bucket, key, convertedKey }
|
||||
|
@ -43,7 +43,7 @@ async function insertFile(bucket, key, stream) {
|
|||
|
||||
async function deleteFile(bucket, key) {
|
||||
const convertedKey = KeyBuilder.getConvertedFolderKey(key)
|
||||
if (!convertedKey.match(/^[0-9a-f]{24}\/[0-9a-f]{24}/i)) {
|
||||
if (!convertedKey.match(/^[0-9a-f]{24}\/([0-9a-f]{24}|v\/[0-9]+\/[a-z]+)/i)) {
|
||||
throw new InvalidParametersError({
|
||||
message: 'key does not match validation regex',
|
||||
info: { bucket, key, convertedKey }
|
||||
|
|
|
@ -111,6 +111,16 @@ describe('FileHandler', function() {
|
|||
})
|
||||
})
|
||||
|
||||
it('should accept templates-api key format', function(done) {
|
||||
KeyBuilder.getConvertedFolderKey.returns(
|
||||
'5ecba29f1a294e007d0bccb4/v/0/pdf'
|
||||
)
|
||||
FileHandler.insertFile(bucket, key, stream, err => {
|
||||
expect(err).not.to.exist
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should throw an error when the key is in the wrong format', function(done) {
|
||||
KeyBuilder.getConvertedFolderKey.returns('wombat')
|
||||
FileHandler.insertFile(bucket, key, stream, err => {
|
||||
|
@ -157,6 +167,16 @@ describe('FileHandler', function() {
|
|||
})
|
||||
})
|
||||
|
||||
it('should accept templates-api key format', function(done) {
|
||||
KeyBuilder.getConvertedFolderKey.returns(
|
||||
'5ecba29f1a294e007d0bccb4/v/0/pdf'
|
||||
)
|
||||
FileHandler.deleteFile(bucket, key, err => {
|
||||
expect(err).not.to.exist
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should throw an error when the key is in the wrong format', function(done) {
|
||||
KeyBuilder.getConvertedFolderKey.returns('wombat')
|
||||
FileHandler.deleteFile(bucket, key, err => {
|
||||
|
|
Loading…
Reference in a new issue