Starting to fix up test cases.
This commit is contained in:
parent
45cc611e1e
commit
f3418044dc
|
@ -136,6 +136,7 @@ module.exports = (
|
||||||
// allow configuring for public access
|
// allow configuring for public access
|
||||||
if ((opts && opts.publicAllowed) || publicEndpoint) {
|
if ((opts && opts.publicAllowed) || publicEndpoint) {
|
||||||
finalise(ctx, { authenticated: false, version, publicEndpoint })
|
finalise(ctx, { authenticated: false, version, publicEndpoint })
|
||||||
|
return next()
|
||||||
} else {
|
} else {
|
||||||
ctx.throw(err.status || 403, err)
|
ctx.throw(err.status || 403, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ exports.ObjectStore = bucket => {
|
||||||
const config = {
|
const config = {
|
||||||
s3ForcePathStyle: true,
|
s3ForcePathStyle: true,
|
||||||
signatureVersion: "v4",
|
signatureVersion: "v4",
|
||||||
|
apiVersion: "2006-03-01",
|
||||||
params: {
|
params: {
|
||||||
Bucket: sanitizeBucket(bucket),
|
Bucket: sanitizeBucket(bucket),
|
||||||
},
|
},
|
||||||
|
@ -102,17 +103,21 @@ exports.makeSureBucketExists = async (client, bucketName) => {
|
||||||
.promise()
|
.promise()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const promises = STATE.bucketCreationPromises
|
const promises = STATE.bucketCreationPromises
|
||||||
|
const doesntExist = err.statusCode === 404,
|
||||||
|
noAccess = err.statusCode === 403
|
||||||
if (promises[bucketName]) {
|
if (promises[bucketName]) {
|
||||||
await promises[bucketName]
|
await promises[bucketName]
|
||||||
} else if (err.statusCode === 404) {
|
} else if (doesntExist || noAccess) {
|
||||||
// bucket doesn't exist create it
|
if (doesntExist) {
|
||||||
promises[bucketName] = client
|
// bucket doesn't exist create it
|
||||||
.createBucket({
|
promises[bucketName] = client
|
||||||
Bucket: bucketName,
|
.createBucket({
|
||||||
})
|
Bucket: bucketName,
|
||||||
.promise()
|
})
|
||||||
await promises[bucketName]
|
.promise()
|
||||||
delete promises[bucketName]
|
await promises[bucketName]
|
||||||
|
delete promises[bucketName]
|
||||||
|
}
|
||||||
// public buckets are quite hidden in the system, make sure
|
// public buckets are quite hidden in the system, make sure
|
||||||
// no bucket is set accidentally
|
// no bucket is set accidentally
|
||||||
if (PUBLIC_BUCKETS.includes(bucketName)) {
|
if (PUBLIC_BUCKETS.includes(bucketName)) {
|
||||||
|
@ -124,7 +129,7 @@ exports.makeSureBucketExists = async (client, bucketName) => {
|
||||||
.promise()
|
.promise()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw err
|
throw new Error("Unable to write to object store bucket.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,12 @@ export async function search(ctx: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function create(ctx: any) {
|
export async function create(ctx: any) {
|
||||||
|
if (!ctx.request.body || !ctx.request.body.useTemplate) {
|
||||||
|
ctx.request.body = {
|
||||||
|
useTemplate: false,
|
||||||
|
...ctx.request.body,
|
||||||
|
}
|
||||||
|
}
|
||||||
await controller.create(ctx)
|
await controller.create(ctx)
|
||||||
await setResponseApp(ctx)
|
await setResponseApp(ctx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ const read = [],
|
||||||
*/
|
*/
|
||||||
write.push(
|
write.push(
|
||||||
new Endpoint("post", "/applications", controller.create).addMiddleware(
|
new Endpoint("post", "/applications", controller.create).addMiddleware(
|
||||||
applicationValidator
|
applicationValidator()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ write.push(
|
||||||
*/
|
*/
|
||||||
write.push(
|
write.push(
|
||||||
new Endpoint("put", "/applications/:appId", controller.update).addMiddleware(
|
new Endpoint("put", "/applications/:appId", controller.update).addMiddleware(
|
||||||
applicationValidator
|
applicationValidator()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,9 @@ const publicRouter = new Router({
|
||||||
})
|
})
|
||||||
|
|
||||||
function addMiddleware(endpoints: any, middleware: CtxFn) {
|
function addMiddleware(endpoints: any, middleware: CtxFn) {
|
||||||
|
if (!endpoints) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!Array.isArray(endpoints)) {
|
if (!Array.isArray(endpoints)) {
|
||||||
endpoints = [endpoints]
|
endpoints = [endpoints]
|
||||||
}
|
}
|
||||||
|
@ -29,8 +32,10 @@ function addMiddleware(endpoints: any, middleware: CtxFn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addToRouter(endpoints: any) {
|
function addToRouter(endpoints: any) {
|
||||||
for (let endpoint of endpoints) {
|
if (endpoints) {
|
||||||
endpoint.apply(publicRouter)
|
for (let endpoint of endpoints) {
|
||||||
|
endpoint.apply(publicRouter)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,12 @@ beforeAll(async () => {
|
||||||
|
|
||||||
afterAll(setup.afterAll)
|
afterAll(setup.afterAll)
|
||||||
|
|
||||||
async function makeRequest(method, endpoint, body, appId) {
|
async function makeRequest(method, endpoint, body, appId = config.getAppId()) {
|
||||||
const extraHeaders = {
|
const extraHeaders = {
|
||||||
"x-budibase-api-key": apiKey,
|
"x-budibase-api-key": apiKey,
|
||||||
"x-budibase-app-id": appId ? appId : config.getAppId(),
|
}
|
||||||
|
if (appId) {
|
||||||
|
extraHeaders["x-budibase-app-id"] = appId
|
||||||
}
|
}
|
||||||
const req = request
|
const req = request
|
||||||
[method](checkSlashesInUrl(`/api/public/v1/${endpoint}`))
|
[method](checkSlashesInUrl(`/api/public/v1/${endpoint}`))
|
||||||
|
@ -39,36 +41,115 @@ describe("check the applications endpoints", () => {
|
||||||
const res = await makeRequest("post", "/applications/search")
|
const res = await makeRequest("post", "/applications/search")
|
||||||
expect(res).toSatisfyApiSpec()
|
expect(res).toSatisfyApiSpec()
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
describe("check the tables endpoints", () => {
|
it("should allow creating an application", async () => {
|
||||||
it("should allow retrieving applications through search", async () => {
|
const res = await makeRequest("post", "/applications", {
|
||||||
const res = await makeRequest("post", "/tables/search")
|
name: "new App"
|
||||||
|
}, null)
|
||||||
|
expect(res).toSatisfyApiSpec()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow updating an application", async () => {
|
||||||
|
const app = config.getApp()
|
||||||
|
const appId = config.getAppId()
|
||||||
|
const res = await makeRequest("put", `/applications/${appId}`, {
|
||||||
|
...app,
|
||||||
|
name: "updated app name",
|
||||||
|
}, appId)
|
||||||
|
expect(res).toSatisfyApiSpec()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow retrieving an application", async () => {
|
||||||
|
const res = await makeRequest("get", `/applications/${config.getAppId()}`)
|
||||||
|
expect(res).toSatisfyApiSpec()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow deleting an application", async () => {
|
||||||
|
const res = await makeRequest("delete", `/applications/${config.getAppId()}`)
|
||||||
expect(res).toSatisfyApiSpec()
|
expect(res).toSatisfyApiSpec()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("check the tables endpoints", () => {
|
||||||
|
it("should allow retrieving tables through search", async () => {
|
||||||
|
const res = await makeRequest("post", "/tables/search")
|
||||||
|
expect(res).toSatisfyApiSpec()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow creating a table", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow updating a table", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow retrieving a table", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow deleting a table", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("check the rows endpoints", () => {
|
describe("check the rows endpoints", () => {
|
||||||
it("should allow retrieving applications through search", async () => {
|
it("should allow retrieving rows through search", async () => {
|
||||||
const res = await makeRequest("post", `/tables/${table._id}/rows/search`, {
|
const res = await makeRequest("post", `/tables/${table._id}/rows/search`, {
|
||||||
query: {
|
query: {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
expect(res).toSatisfyApiSpec()
|
expect(res).toSatisfyApiSpec()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should allow creating a row", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow updating a row", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow retrieving a row", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow deleting a row", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("check the users endpoints", () => {
|
describe("check the users endpoints", () => {
|
||||||
it("should allow retrieving applications through search", async () => {
|
it("should allow retrieving users through search", async () => {
|
||||||
const res = await makeRequest("post", "/users/search")
|
const res = await makeRequest("post", "/users/search")
|
||||||
expect(res).toSatisfyApiSpec()
|
expect(res).toSatisfyApiSpec()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should allow creating a user", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow updating a user", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow retrieving a user", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow deleting a user", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("check the queries endpoints", () => {
|
describe("check the queries endpoints", () => {
|
||||||
it("should allow retrieving applications through search", async () => {
|
it("should allow retrieving queries through search", async () => {
|
||||||
const res = await makeRequest("post", "/queries/search")
|
const res = await makeRequest("post", "/queries/search")
|
||||||
expect(res).toSatisfyApiSpec()
|
expect(res).toSatisfyApiSpec()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should allow executing a query", async () => {
|
||||||
|
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -205,4 +205,15 @@ exports.automationValidator = (existing = false) => {
|
||||||
}).unknown(true))
|
}).unknown(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.applicationValidator = () => {}
|
exports.applicationValidator = () => {
|
||||||
|
// prettier-ignore
|
||||||
|
return joiValidator.body(Joi.object({
|
||||||
|
_id: OPTIONAL_STRING,
|
||||||
|
_rev: OPTIONAL_STRING,
|
||||||
|
name: Joi.string().required(),
|
||||||
|
url: OPTIONAL_STRING,
|
||||||
|
template: Joi.object({
|
||||||
|
templateString: OPTIONAL_STRING,
|
||||||
|
}).unknown(true),
|
||||||
|
}).unknown(true))
|
||||||
|
}
|
||||||
|
|
|
@ -49,6 +49,10 @@ class TestConfiguration {
|
||||||
return this.request
|
return this.request
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getApp() {
|
||||||
|
return this.app
|
||||||
|
}
|
||||||
|
|
||||||
getAppId() {
|
getAppId() {
|
||||||
return this.appId
|
return this.appId
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue