mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Use GRAPHQL_URI env var instead establishing ACTIVITYPUB env vars + http Signature test fix
This commit is contained in:
parent
6f075e08c5
commit
48ed75b6e4
@ -13,7 +13,6 @@ import as from 'activitystrea.ms'
|
||||
import NitroDataSource from './NitroDataSource'
|
||||
import router from './routes'
|
||||
import dotenv from 'dotenv'
|
||||
import { resolve } from 'path'
|
||||
import Collections from './Collections'
|
||||
const debug = require('debug')('ea')
|
||||
|
||||
@ -22,19 +21,19 @@ let activityPub = null
|
||||
export { activityPub }
|
||||
|
||||
export default class ActivityPub {
|
||||
constructor (domain, port) {
|
||||
constructor (domain, port, uri) {
|
||||
if (domain === 'localhost') { this.domain = `${domain}:${port}` } else { this.domain = domain }
|
||||
this.port = port
|
||||
this.dataSource = new NitroDataSource(this.domain)
|
||||
this.dataSource = new NitroDataSource(uri)
|
||||
this.collections = new Collections(this.dataSource)
|
||||
}
|
||||
static init (server) {
|
||||
if (!activityPub) {
|
||||
dotenv.config({ path: resolve('src', 'activitypub', '.env') })
|
||||
const port = process.env.ACTIVITYPUB_PORT
|
||||
activityPub = new ActivityPub(process.env.ACTIVITYPUB_DOMAIN || 'localhost', port || 4100)
|
||||
dotenv.config()
|
||||
const url = new URL(process.env.GRAPHQL_URI)
|
||||
activityPub = new ActivityPub(url.hostname || 'localhost', url.port || 4000, url.origin)
|
||||
|
||||
// integrated into "server" express framework
|
||||
// integrated into "server's" express framework
|
||||
server.express.set('ap', activityPub)
|
||||
server.express.use(router)
|
||||
debug('ActivityPub middleware added to the express service')
|
||||
|
||||
@ -19,25 +19,21 @@ import { setContext } from 'apollo-link-context'
|
||||
import { InMemoryCache } from 'apollo-cache-inmemory'
|
||||
import fetch from 'node-fetch'
|
||||
import { ApolloClient } from 'apollo-client'
|
||||
import dotenv from 'dotenv'
|
||||
import uuid from 'uuid'
|
||||
import encode from '../jwt/encode'
|
||||
import { resolve } from 'path'
|
||||
import trunc from 'trunc-html'
|
||||
const debug = require('debug')('ea:nitro-datasource')
|
||||
|
||||
dotenv.config({ path: resolve('src', 'activitypub', '.env') })
|
||||
|
||||
export default class NitroDataSource {
|
||||
constructor (domain) {
|
||||
this.domain = domain
|
||||
constructor (uri) {
|
||||
this.uri = uri
|
||||
const defaultOptions = {
|
||||
query: {
|
||||
fetchPolicy: 'network-only',
|
||||
errorPolicy: 'all'
|
||||
}
|
||||
}
|
||||
const link = createHttpLink({ uri: process.env.GRAPHQL_URI, fetch: fetch }) // eslint-disable-line
|
||||
const link = createHttpLink({ uri: this.uri, fetch: fetch }) // eslint-disable-line
|
||||
const cache = new InMemoryCache()
|
||||
const authLink = setContext((_, { headers }) => {
|
||||
// generate the authentication token (maybe from env? Which user?)
|
||||
|
||||
@ -7,7 +7,6 @@ import { expect } from 'chai'
|
||||
const factory = Factory()
|
||||
|
||||
describe('Signature creation and verification', () => {
|
||||
process.env.PRIVATE_KEY_PASSPHRASE = 'test-password'
|
||||
let user = null
|
||||
let client = null
|
||||
const headers = {
|
||||
@ -43,8 +42,7 @@ describe('Signature creation and verification', () => {
|
||||
beforeEach(() => {
|
||||
const signer = crypto.createSign('rsa-sha256')
|
||||
signer.update('(request-target): post /activitypub/users/max/inbox\ndate: 2019-03-08T14:35:45.759Z\nhost: democracy-app.de\ncontent-type: application/json')
|
||||
console.log(JSON.stringify(user, null, 2))
|
||||
signatureB64 = signer.sign({ key: user.privateKey, passphrase: 'test-password' }, 'base64')
|
||||
signatureB64 = signer.sign({ key: user.privateKey, passphrase: 'a7dsf78sadg87ad87sfagsadg78' }, 'base64')
|
||||
})
|
||||
it('creates a Signature with given privateKey, keyId, url and headers (default algorithm: "rsa-sha256")', () => {
|
||||
const httpSignature = createSignature(user.privateKey, 'https://human-connection.org/activitypub/users/lea#main-key', 'https://democracy-app.de/activitypub/users/max/inbox', headers)
|
||||
@ -65,7 +63,6 @@ describe('Signature creation and verification', () => {
|
||||
it('verifies a Signature by ', async () => {
|
||||
headers['Signature'] = httpSignature
|
||||
const isVerified = await verifySignature('https://democracy-app.de/activitypub/users/max/inbox', headers)
|
||||
console.log(JSON.stringify(isVerified, null, 2))
|
||||
expect(isVerified).to.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@ -24,7 +24,7 @@ export function generateRsaKeyPair () {
|
||||
|
||||
// signing
|
||||
export function createSignature (privKey, keyId, url, headers = {}, algorithm = 'rsa-sha256') {
|
||||
if (!SUPPORTED_HASH_ALGORITHMS.includes(algorithm)) { return throw Error(`SIGNING: Unsupported hashing algorithm = ${algorithm}`) }
|
||||
if (!SUPPORTED_HASH_ALGORITHMS.includes(algorithm)) { throw Error(`SIGNING: Unsupported hashing algorithm = ${algorithm}`) }
|
||||
const signer = crypto.createSign(algorithm)
|
||||
const signingString = constructSigningString(url, headers)
|
||||
signer.update(signingString)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user