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:
commit
8bddcfc4bc
@ -42,10 +42,9 @@ 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) => {
|
||||
expect(err instanceof Error).toEqual(true)
|
||||
})
|
||||
await store.dispatch('Login/fetchLogin', 'pleroma.io').catch((err: Error) => {
|
||||
expect(err instanceof Error).toEqual(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('success', () => {
|
||||
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user