aboutsummaryrefslogtreecommitdiff
path: root/vnext/server/middleware
diff options
context:
space:
mode:
Diffstat (limited to 'vnext/server/middleware')
-rw-r--r--vnext/server/middleware/mastodon.spec.js17
-rw-r--r--vnext/server/middleware/webfinger.js17
-rw-r--r--vnext/server/middleware/webfinger.spec.js31
3 files changed, 60 insertions, 5 deletions
diff --git a/vnext/server/middleware/mastodon.spec.js b/vnext/server/middleware/mastodon.spec.js
new file mode 100644
index 00000000..648923e4
--- /dev/null
+++ b/vnext/server/middleware/mastodon.spec.js
@@ -0,0 +1,17 @@
+import request from 'supertest'
+import express from 'express'
+import { instance } from './mastodon'
+
+const app = express()
+app.get('/instance', instance)
+
+describe('Mastodon API middleware', () => {
+ it('Inactive users should not be included in Instance response', async () => {
+ return request(app)
+ .get('/instance')
+ .expect(200)
+ .then(response => {
+ expect(response.body.usage.users.active_month).toStrictEqual(1)
+ })
+ })
+})
diff --git a/vnext/server/middleware/webfinger.js b/vnext/server/middleware/webfinger.js
index 9800fc01..873387b3 100644
--- a/vnext/server/middleware/webfinger.js
+++ b/vnext/server/middleware/webfinger.js
@@ -1,5 +1,7 @@
import config from 'config'
import addrparser from 'address-rfc2822'
+import debug from 'debug'
+var log = debug('webfinger')
import { getUserByName } from '../db/Users'
@@ -18,7 +20,8 @@ export const webfinger = async (req, res) => {
const address = addresses[0]
const ourAddress = new URL(baseUrl)
if (address.host() === ourAddress.hostname) {
- const user = await getUserByName(addresses[0].user())
+ const name = addresses[0].user()
+ const user = await getUserByName(name)
if (user) {
return res.json({
subject: resource,
@@ -31,16 +34,20 @@ export const webfinger = async (req, res) => {
]
})
} else {
- return res.status(404).send('User not found')
+ log(`User not found: ${name}`)
+ return res.status(404).end()
}
} else {
- return res.status(404).send('Address not found')
+ log(`Address not found: ${address.host()}`)
+ return res.status(404).end()
}
} else {
- return res.status(400).send('Invalid resource')
+ log(`Invalid resource: ${resource}`)
+ return res.status(400).end()
}
}
- res.status(400).send('Missing `resource` param')
+ log('Missing `resource` param')
+ res.status(400)
}
const parseAddress = (address = '') => {
diff --git a/vnext/server/middleware/webfinger.spec.js b/vnext/server/middleware/webfinger.spec.js
new file mode 100644
index 00000000..fde2e428
--- /dev/null
+++ b/vnext/server/middleware/webfinger.spec.js
@@ -0,0 +1,31 @@
+import request from 'supertest'
+import express from 'express'
+import { webfinger } from './webfinger'
+
+const app = express()
+app.get('/webfinger', webfinger)
+
+describe('WebFinger middleware', () => {
+ it('Existing user response should have a subject and links', async () => {
+ const resource = 'acct:ugnich@juick.com'
+ const response = await request(app)
+ .get(`/webfinger?resource=${resource}`)
+ expect(response.status).toStrictEqual(200)
+ expect(response.body.subject).toStrictEqual(resource)
+ expect(response.body.links.length).toStrictEqual(1)
+ expect(response.body.links[0].href).toStrictEqual('https://juick.com/u/ugnich')
+ })
+ it('Unknown user should return 404', async () => {
+ const resource = 'acct:durov@juick.com'
+ const response = await request(app)
+ .get(`/webfinger?resource=${resource}`)
+ expect(response.status).toStrictEqual(404)
+ })
+ it('Invalid input should return 400', async () => {
+ const resource = ';DROP TABLE users'
+ const response = await request(app)
+ .get(`/webfinger?resource=${resource}`)
+ expect(response.status).toStrictEqual(400)
+ })
+})
+