Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let app = require('../lib/server')
let request = require('supertest').agent(app.listen())
let user = require('../lib/user')
let redis = require('../lib/redis')
let co = require('co')
let url = require('url')
let crypto = require('crypto')
let fs = require('fs')
let config = require('../lib/config')
let expect = require('unexpected')
let sinon = require('sinon')
let http = require('http-call').HTTP
let storageBackends = require('./_storage_backends')
// make sure this user is in the htpasswd file
const testUser = {name: 'test', password: 'test'}
function * deleteItems (prefix) {
let items = yield config.storage.list(prefix)
for (let item of items) {
console.log(`deleting ${item}`)
yield config.storage.delete(item)
}
}
function bearer (token) {
return function (request) {
request.set('Authorization', `Bearer ${token}`)
const http = require('http-call').HTTP
const maxRetries = 10
async function call (url, out, retries) {
try {
let {response} = await http.stream(url)
response.on('data', function (d) {
out.write(d)
})
return await new Promise(function (resolve, reject) {
response.on('error', reject)
response.on('end', resolve)
})
} catch (err) {
if (err.statusCode === 404 && retries <= maxRetries) {
return new Promise(function (resolve, reject) {
setTimeout(function () {