const storageDir = STORAGE[storage]
return new Promise((res, rej) => {
- rimraf(storageDir, function (err) {
+ rimraf(storageDir, err => {
if (err) return rej(err)
console.info('%s deleted.', storageDir)
.then(user => {
if (!user) {
console.error('User unknown.')
- return
+ process.exit(-1)
}
const readline = require('readline')
-import { readFileSync, writeFileSync } from 'fs'
-import { join } from 'path'
-import * as parseTorrent from 'parse-torrent'
+import * as Promise from 'bluebird'
-import { CONFIG, STATIC_PATHS } from '../server/initializers/constants'
import { database as db } from '../server/initializers/database'
import { hasFriends } from '../server/lib/friends'
return db.Video.list()
})
.then(videos => {
+ const tasks: Promise<any>[] = []
+
videos.forEach(video => {
+ console.log('Updating video ' + video.uuid)
+
video.VideoFiles.forEach(file => {
- video.createTorrentAndSetInfoHash(file)
+ tasks.push(video.createTorrentAndSetInfoHash(file))
})
})
+ return Promise.all(tasks)
+ })
+ .then(() => {
process.exit(0)
})
}
function root () {
- // We are in /dist/helpers/utils.js
- return join(__dirname, '..', '..', '..')
+ // We are in /helpers/utils.js
+ const paths = [ __dirname, '..', '..' ]
+
+ // We are under /dist directory
+ if (process.mainModule.filename.endsWith('.ts') === false) {
+ paths.push('..')
+ }
+
+ return join.apply(null, paths)
}
function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> {
+import 'express-validator'
+
function exists (value: any) {
return value !== undefined && value !== null
}
import * as validator from 'validator'
+import 'express-validator'
import { isArray, exists } from './misc'
import { isTestInstance } from '../core-utils'
+import 'express-validator'
import { has, values } from 'lodash'
import {
import { values } from 'lodash'
import * as validator from 'validator'
+import 'express-validator'
import { exists } from './misc'
import { CONSTRAINTS_FIELDS, USER_ROLES } from '../../initializers'
import { values } from 'lodash'
import * as validator from 'validator'
+import 'express-validator'
import 'multer'
import {
// Do not use barrel, we need to load database first
import { logger } from '../helpers/logger'
import { isTestInstance, readdirPromise } from '../helpers/core-utils'
-import {
- ApplicationModel,
- AuthorModel,
- JobModel,
- OAuthClientModel,
- OAuthTokenModel,
- PodModel,
- RequestModel,
- RequestToPodModel,
- RequestVideoEventModel,
- RequestVideoQaduModel,
- TagModel,
- UserModel,
- UserVideoRateModel,
- VideoAbuseModel,
- BlacklistedVideoModel,
- VideoFileModel,
- VideoTagModel,
- VideoModel
-} from '../models'
+
+import { VideoModel } from './../models/video/video-interface'
+import { VideoTagModel } from './../models/video/video-tag-interface'
+import { BlacklistedVideoModel } from './../models/video/video-blacklist-interface'
+import { VideoFileModel } from './../models/video/video-file-interface'
+import { VideoAbuseModel } from './../models/video/video-abuse-interface'
+import { UserModel } from './../models/user/user-interface'
+import { UserVideoRateModel } from './../models/user/user-video-rate-interface'
+import { TagModel } from './../models/video/tag-interface'
+import { RequestModel } from './../models/request/request-interface'
+import { RequestVideoQaduModel } from './../models/request/request-video-qadu-interface'
+import { RequestVideoEventModel } from './../models/request/request-video-event-interface'
+import { RequestToPodModel } from './../models/request/request-to-pod-interface'
+import { PodModel } from './../models/pod/pod-interface'
+import { OAuthTokenModel } from './../models/oauth/oauth-token-interface'
+import { OAuthClientModel } from './../models/oauth/oauth-client-interface'
+import { JobModel } from './../models/job/job-interface'
+import { AuthorModel } from './../models/video/author-interface'
+import { ApplicationModel } from './../models/application/application-interface'
const dbname = CONFIG.DATABASE.DBNAME
const username = CONFIG.DATABASE.USERNAME
import * as Sequelize from 'sequelize'
import * as Promise from 'bluebird'
-import { UserModel } from '../user'
+import { UserModel } from '../user/user-interface'
export type OAuthTokenInfo = {
refreshToken: string
import * as Promise from 'bluebird'
import { AbstractRequestClass } from './abstract-request-interface'
-import { PodInstance, PodAttributes } from '../pod'
+import { PodInstance, PodAttributes } from '../pod/pod-interface'
import { RequestEndpoint } from '../../../shared/models/request-scheduler.model'
export type RequestsGrouped = {
import * as Promise from 'bluebird'
import { AbstractRequestClass, AbstractRequestToPodClass } from './abstract-request-interface'
-import { VideoInstance } from '../video'
-import { PodInstance } from '../pod'
+import { VideoInstance } from '../video/video-interface'
+import { PodInstance } from '../pod/pod-interface'
import { RequestVideoEventType } from '../../../shared/models/request-scheduler.model'
import * as Promise from 'bluebird'
import { AbstractRequestClass, AbstractRequestToPodClass } from './abstract-request-interface'
-import { VideoInstance } from '../video'
-import { PodInstance } from '../pod'
+import { VideoInstance } from '../video/video-interface'
+import { PodInstance } from '../pod/pod-interface'
import { RequestVideoQaduType } from '../../../shared/models/request-scheduler.model'
import * as Sequelize from 'sequelize'
import * as Promise from 'bluebird'
-import { PodInstance } from '../pod'
+import { PodInstance } from '../pod/pod-interface'
export namespace AuthorMethods {
export type FindOrCreateAuthor = (
import * as Sequelize from 'sequelize'
import * as Promise from 'bluebird'
-import { PodInstance } from '../pod'
+import { PodInstance } from '../pod/pod-interface'
import { ResultList } from '../../../shared'
// Don't use barrel, import just what we need
return createTorrentPromise(this.getVideoFilePath(videoFile), options)
.then(torrent => {
const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
+ logger.info('Creating torrent %s.', filePath)
+
return writeFilePromise(filePath, torrent).then(() => torrent)
})
.then(torrent => {
--- /dev/null
+// Order of the tests we want to execute
+import './reset-password'
--- /dev/null
+import 'mocha'
+
+import {
+ createUser,
+ execCLI,
+ flushTests,
+ getEnvCli,
+ killallServers,
+ login,
+ runServer,
+ ServerInfo,
+ setAccessTokensToServers
+} from '../utils'
+
+describe('Test reset password scripts', function () {
+ let server: ServerInfo
+
+ before(async function () {
+ this.timeout(30000)
+
+ await flushTests()
+ server = await runServer(1)
+ await setAccessTokensToServers([ server ])
+
+ await createUser(server.url, server.accessToken, 'user_1', 'super password')
+ })
+
+ it('Should change the user password from CLI', async function () {
+ this.timeout(20000)
+
+ const env = getEnvCli(server)
+ await execCLI(`echo coucou | ${env} npm run reset-password -- -u user_1`)
+
+ await login(server.url, server.client, { username: 'user_1', password: 'coucou' }, 200)
+ })
+
+ after(async function () {
+ killallServers([ server ])
+
+ // Keep the logs if the test failed
+ if (this['ok']) {
+ await flushTests()
+ }
+ })
+})
--- /dev/null
+import 'mocha'
+import * as chai from 'chai'
+const expect = chai.expect
+
+import {
+ execCLI,
+ flushTests,
+ getEnvCli,
+ getVideosList,
+ killallServers,
+ parseTorrentVideo,
+ runServer,
+ ServerInfo,
+ setAccessTokensToServers,
+ uploadVideo
+} from '../utils'
+
+describe('Test update host scripts', function () {
+ let server: ServerInfo
+
+ before(async function () {
+ this.timeout(30000)
+
+ await flushTests()
+
+ const overrideConfig = {
+ webserver: {
+ port: 9256
+ }
+ }
+ server = await runServer(1, overrideConfig)
+ await setAccessTokensToServers([ server ])
+
+ // Upload two videos for our needs
+ const videoAttributes = {}
+ await uploadVideo(server.url, server.accessToken, videoAttributes)
+ await uploadVideo(server.url, server.accessToken, videoAttributes)
+ })
+
+ it('Should update torrent hosts', async function () {
+ this.timeout(20000)
+
+ killallServers([ server ])
+ server = await runServer(1)
+
+ const env = getEnvCli(server)
+ await execCLI(`${env} npm run update-host`)
+
+ const res = await getVideosList(server.url)
+ const videos = res.body.data
+
+ expect(videos[0].files[0].magnetUri).to.contain('localhost%3A9001%2Ftracker%2Fsocket')
+ expect(videos[0].files[0].magnetUri).to.contain('localhost%3A9001%2Fstatic%2Fwebseed%2F')
+
+ expect(videos[1].files[0].magnetUri).to.contain('localhost%3A9001%2Ftracker%2Fsocket')
+ expect(videos[1].files[0].magnetUri).to.contain('localhost%3A9001%2Fstatic%2Fwebseed%2F')
+
+ const torrent = await parseTorrentVideo(server, videos[0].uuid)
+ expect(torrent.announce[0]).to.equal('ws://localhost:9001/tracker/socket')
+ expect(torrent.urlList[0]).to.contain('http://localhost:9001/static/webseed')
+ })
+
+ after(async function () {
+ killallServers([ server ])
+
+ // Keep the logs if the test failed
+ if (this['ok']) {
+ await flushTests()
+ }
+ })
+})
// Order of the tests we want to execute
import './client'
import './api/'
+import './cli/'
--- /dev/null
+import { exec } from 'child_process'
+
+import { ServerInfo } from './servers'
+
+function getEnvCli (server?: ServerInfo) {
+ return `NODE_ENV=test NODE_APP_INSTANCE=${server.serverNumber}`
+}
+
+async function execCLI (command: string) {
+ return new Promise((res, rej) => {
+ exec(command, (err, stdout, stderr) => {
+ if (err) return rej(err)
+
+ return res(stdout)
+ })
+ })
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+ execCLI,
+ getEnvCli
+}
+export * from './cli'
export * from './clients'
export * from './config'
export * from './login'
app: ChildProcess,
url: string
host: string
+ serverNumber: number
client: {
id: string,
})
}
-function runServer (serverNumber: number) {
+function runServer (serverNumber: number, configOverride?: Object) {
const server: ServerInfo = {
app: null,
+ serverNumber: serverNumber,
url: `http://localhost:${9000 + serverNumber}`,
host: `localhost:${9000 + serverNumber}`,
client: {
const env = Object.create(process.env)
env['NODE_ENV'] = 'test'
env['NODE_APP_INSTANCE'] = serverNumber.toString()
+
+ if (configOverride !== undefined) {
+ env['NODE_CONFIG'] = JSON.stringify(configOverride)
+ }
+
const options = {
silent: true,
env: env,
+import { readFile } from 'fs'
import * as request from 'supertest'
import { join, isAbsolute } from 'path'
+import * as parseTorrent from 'parse-torrent'
import { makeGetRequest } from './requests'
import { readFilePromise } from './miscs'
+import { ServerInfo } from './servers'
type VideoAttributes = {
name?: string
.expect(specialStatus)
}
+function parseTorrentVideo (server: ServerInfo, videoUUID: string) {
+ return new Promise<any>((res, rej) => {
+ const torrentPath = join(__dirname, '..', '..', '..', 'test' + server.serverNumber, 'torrents', videoUUID + '.torrent')
+ readFile(torrentPath, (err, data) => {
+ if (err) return rej(err)
+
+ return res(parseTorrent(data))
+ })
+ })
+}
+
// ---------------------------------------------------------------------------
export {
testVideoImage,
uploadVideo,
updateVideo,
- rateVideo
+ rateVideo,
+ parseTorrentVideo
}