2021-03-07 20:41:54 +01:00
|
|
|
|
2021-03-08 17:01:28 +01:00
|
|
|
describe("webmention receiver validate tests", () => {
|
2021-03-07 20:41:54 +01:00
|
|
|
|
2021-03-08 10:25:02 +01:00
|
|
|
const validhttpurl = "http://brainbaking.com/bla"
|
|
|
|
const validhttpsurl = "https://brainbaking.com/blie"
|
|
|
|
const urlfrominvaliddomain = "http://brainthe.bake/jup"
|
2021-03-07 20:41:54 +01:00
|
|
|
const invalidurl = "lolzw"
|
|
|
|
|
2021-03-08 13:59:20 +01:00
|
|
|
const { validate } = require('../../src/webmention/receive')
|
|
|
|
|
|
|
|
|
2021-03-07 20:41:54 +01:00
|
|
|
test("is valid if source and target https urls", () => {
|
2021-03-08 10:25:02 +01:00
|
|
|
const result = validate({
|
|
|
|
type: "application/x-www-form-urlencoded",
|
|
|
|
body: {
|
|
|
|
source: validhttpsurl + "1",
|
|
|
|
target: validhttpsurl + "2"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(result).toBe(true)
|
|
|
|
})
|
2021-03-08 17:55:44 +01:00
|
|
|
test("is NOT valid if target is a valid url but not form valid domain", () => {
|
2021-03-08 10:25:02 +01:00
|
|
|
const result = validate({
|
|
|
|
type: "application/x-www-form-urlencoded",
|
|
|
|
body: {
|
2021-03-08 17:55:44 +01:00
|
|
|
source: validhttpsurl + "2",
|
|
|
|
target: urlfrominvaliddomain
|
2021-03-08 10:25:02 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(result).toBe(false)
|
|
|
|
})
|
|
|
|
test("is NOT valid if source and target are the same urls", () => {
|
2021-03-07 20:41:54 +01:00
|
|
|
const result = validate({
|
|
|
|
type: "application/x-www-form-urlencoded",
|
|
|
|
body: {
|
|
|
|
source: validhttpsurl,
|
|
|
|
target: validhttpsurl
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-03-08 10:25:02 +01:00
|
|
|
expect(result).toBe(false)
|
2021-03-07 20:41:54 +01:00
|
|
|
})
|
|
|
|
test("is valid if source and target http urls", () => {
|
|
|
|
const result = validate({
|
|
|
|
type: "application/x-www-form-urlencoded",
|
|
|
|
body: {
|
2021-03-08 10:25:02 +01:00
|
|
|
source: validhttpurl + "1",
|
|
|
|
target: validhttpurl + "2"
|
2021-03-07 20:41:54 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(result).toBe(true)
|
|
|
|
})
|
|
|
|
test("is NOT valid if source is not a valid url", () => {
|
|
|
|
const result = validate({
|
|
|
|
type: "application/x-www-form-urlencoded",
|
|
|
|
body: {
|
|
|
|
source: invalidurl,
|
|
|
|
target: validhttpurl
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(result).toBe(false)
|
|
|
|
})
|
|
|
|
test("is NOT valid if target is not a valid url", () => {
|
|
|
|
const result = validate({
|
|
|
|
type: "application/x-www-form-urlencoded",
|
|
|
|
body: {
|
|
|
|
source: validhttpurl,
|
|
|
|
target: invalidurl
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(result).toBe(false)
|
|
|
|
})
|
|
|
|
test("is NOT valid if source is missing", () => {
|
|
|
|
const result = validate({
|
|
|
|
type: "application/x-www-form-urlencoded",
|
|
|
|
body: {
|
|
|
|
target: validhttpurl
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(result).toBe(false)
|
|
|
|
})
|
|
|
|
test("is NOT valid if target is missing", () => {
|
|
|
|
const result = validate({
|
|
|
|
type: "application/x-www-form-urlencoded",
|
|
|
|
body: {
|
|
|
|
source: validhttpurl
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(result).toBe(false)
|
|
|
|
})
|
|
|
|
test("is NOT valid if no valid encoded form", () => {
|
|
|
|
const result = validate({
|
|
|
|
type: "ow-mai-got",
|
|
|
|
body: {
|
|
|
|
source: validhttpurl,
|
|
|
|
target: validhttpurl
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(result).toBe(false)
|
|
|
|
})
|
|
|
|
test("is NOT valid if body is missing", () => {
|
|
|
|
const result = validate({
|
|
|
|
type: "application/x-www-form-urlencoded"
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(result).toBe(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|