1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-02-01 01:47:01 +01:00

Merge pull request #1032 from h3poteto/iss-1028

refs #1028 Confirm ActivityPub instance to read host-meta before login
This commit is contained in:
AkiraFukushima 2019-09-14 22:36:30 +09:00 committed by GitHub
commit 8bddcfc4bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -42,8 +42,7 @@ describe('Login', () => {
ipcMain.once('get-auth-url', event => {
event.sender.send('error-get-auth-url', new Error())
})
await store.dispatch('Login/fetchLogin', 'pleroma.io')
.catch((err: Error) => {
await store.dispatch('Login/fetchLogin', 'pleroma.io').catch((err: Error) => {
expect(err instanceof Error).toEqual(true)
})
})
@ -72,9 +71,10 @@ describe('Login', () => {
// https://github.com/facebook/jest/issues/6552
// https://github.com/kulshekhar/ts-jest/issues/828
const mockedAxios = axios as any
const res: Promise<object> = new Promise<object>(resolve => {
const res: Promise<{}> = new Promise<{}>(resolve => {
resolve({
data: 'test'
data:
'<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="https://pleroma.io/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>'
})
})
mockedAxios.get.mockImplementation(() => res)

View File

@ -46,9 +46,17 @@ const actions: ActionTree<LoginState, RootState> = {
},
confirmInstance: async ({ commit }, domain: string): Promise<boolean> => {
commit(MUTATION_TYPES.CHANGE_SEARCHING, true)
await axios.get(`https://${domain}/api/v1/instance`).finally(() => {
// https://gist.github.com/okapies/60d62d0df0163bbfb4ab09c1766558e8
// Check /.well-known/host-meta to confirm mastodon instance.
const res = await axios.get(`https://${domain}/.well-known/host-meta`).finally(() => {
commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
})
const parser = new DOMParser()
const dom = parser.parseFromString(res.data, 'text/xml')
const link = dom.getElementsByTagName('Link')[0].outerHTML
if (!link.includes(`https://${domain}/.well-known/webfinger`)) {
throw new Error('domain is not activity pub')
}
commit(MUTATION_TYPES.CHANGE_INSTANCE, domain)
return true
}