it('verify fetching embed code goes to the configured MediaCore instance in multi-tenant scenario', function(callback) { // Create a MediaCore server to be accessed for files in the gt tenant and configure the gatech tenant to use it TestsUtil.createTestServer(function(gtMediaCoreApp, gtMediaCoreServer, gtMediaCorePort) { MediaCoreTestsUtil.enableMediaCore(gtAdminRestContext, util.format('http://127.0.0.1:%s', gtMediaCorePort), 'gtKey', 'gtSecret', 67890, function() { // Create the cambridge and gatech users to create and access files with TestsUtil.generateTestUsers(camAdminRestContext, 1, function(err, users) { assert.ok(!err); var camUser = _.values(users)[0]; TestsUtil.generateTestUsers(gtAdminRestContext, 1, function(err, users) { var gtUser = _.values(users)[0]; // Create the content items for cambridge and gatech that we'll test with, and give them mediaCoreIds RestAPI.Content.createFile(camUser.restContext, 'test video', null, 'public', _getVideoStream, null, null, null, function(err, camContent) { assert.ok(!err); RestAPI.Content.setPreviewItems(camAdminRestContext, camContent.id, camContent.latestRevisionId, 'done', {}, {}, {}, {'mediaCoreId': 12345}, function(err) { assert.ok(!err); RestAPI.Content.createFile(gtUser.restContext, 'test video', null, 'public', _getVideoStream, null, null, null, function(err, gtContent) { assert.ok(!err); RestAPI.Content.setPreviewItems(gtAdminRestContext, gtContent.id, gtContent.latestRevisionId, 'done', {}, {}, {}, {'mediaCoreId': 67890}, function(err) { assert.ok(!err); // Set up the embedcode handlers for the cambridge and gatech MediaCore instances mediaCoreApp.get('/api2/media/:mediaCoreId/embedcode', function(req, res) { assert.equal(req.params.mediaCoreId, 12345); res.status(200).send({'html': '<iframe src="http://cambridge.mediacore.tv"></iframe>'}); }); gtMediaCoreApp.get('/api2/media/:mediaCoreId/embedcode', function(req, res) { assert.equal(req.params.mediaCoreId, 67890); res.status(200).send({'html': '<iframe src="http://gatech.mediacore.tv"></iframe>'}); }); // Access the cambridge tenant file with the gatech user to ensure the request still goes to the cambridge MediaCore instance RestAPI.MediaCore.getEmbedCode(gtUser.restContext, camContent.id, function(err, embedCode) { assert.ok(!err); assert.strictEqual(embedCode.html.indexOf('<iframe src="http://cambridge.mediacore.tv'), 0); RestAPI.MediaCore.getEmbedCode(camUser.restContext, gtContent.id, function(err, embedCode) { assert.ok(!err); assert.strictEqual(embedCode.html.indexOf('<iframe src="http://gatech.mediacore.tv'), 0); return callback(); }); }); }); }); }); }); }); }); }); }); });
beforeEach(function(callback) { globalAdminRestContext = TestsUtil.createGlobalAdminRestContext(); camAdminRestContext = TestsUtil.createTenantAdminRestContext(global.oaeTests.tenants.cam.host); gtAdminRestContext = TestsUtil.createTenantAdminRestContext(global.oaeTests.tenants.gt.host); // Start the express server TestsUtil.createTestServer(function(_app, _server, _port) { app = _app; server = _server; port = _port; // Enable the MediaCore preview processor and configure it to talk to our new web server MediaCoreTestsUtil.enableMediaCore(camAdminRestContext, util.format('http://127.0.0.1:%s', port), 'camKey', 'camSecret', 12345, callback); }); });
it('verify video uploads from different tenants honour tenant-specific configuration', function(callback) { // Cambridge has a test server setup to some random port, we'll start up another for gatech to ensure the separate URL configuration is honoured TestsUtil.createTestServer(function(gtMediaCoreApp, gtMediaCoreServer, gtMediaCorePort) { var gtMediaCoreUrl = util.format('http://127.0.0.1:%s', gtMediaCorePort); // Setup the gatech tenant to use the 2nd MediaCore server MediaCoreTestsUtil.enableMediaCore(gtAdminRestContext, gtMediaCoreUrl, 'gtKey', 'gtSecret', 67890, function(err) { assert.ok(!err); // Tracks whether or not publish requests were received by the cam and gt tenants var camRequestReceived = false; var gtRequestReceived = false; /** * Ensure we exit when we receive a MediaCore upload for each uploaded file */ var _finishMediaCoreRequest = function() { if (camRequestReceived && gtRequestReceived) { // The test was successful, we expected one from each tenant. If we do not receive each request, this test will time out and that // is what indicates the error return callback(); } }; // Apply routes to the cam and gt MediaCore servers to verify the incoming config information app.post('/api2/media', function(req, res) { camRequestReceived = true; assert.equal(req.body.collection_id, 12345); assert.equal(req.body.title, 'File from cam tenant'); res.send(400, {}); return _finishMediaCoreRequest(); }); gtMediaCoreApp.post('/api2/media', function(req, res) { gtRequestReceived = true; assert.equal(req.body.collection_id, 67890); assert.equal(req.body.title, 'File from gt tenant'); res.send(400, {}); return _finishMediaCoreRequest(); }); // Generate our test users with which to create files TestsUtil.generateTestUsers(camAdminRestContext, 1, function(err, camUser) { assert.ok(!err); camUser = _.values(camUser)[0]; TestsUtil.generateTestUsers(gtAdminRestContext, 1, function(err, gtUser) { assert.ok(!err); gtUser = _.values(gtUser)[0]; // Create a video file for each tenant RestAPI.Content.createFile(camUser.restContext, 'File from cam tenant', null, 'public', _getVideoStream, null, null, function(err, camContent) { assert.ok(!err); RestAPI.Content.createFile(gtUser.restContext, 'File from gt tenant', null, 'public', _getVideoStream, null, null, function(err, gtContent) { assert.ok(!err); // Get the revisions that we can use for the mock preview contexts RestAPI.Content.getRevision(camUser.restContext, camContent.id, camContent.latestRevisionId, function(err, camRevision) { assert.ok(!err); RestAPI.Content.getRevision(gtUser.restContext, gtContent.id, gtContent.latestRevisionId, function(err, gtRevision) { assert.ok(!err); // Create the mock preview contexts we can use to invoke the MediaCore preview processor var camMockPreviewContext = { 'contentId': camContent.id, 'revisionId': camRevision.revisionId, 'revision': camRevision, 'download': function(callback) { return callback(null, __dirname + '/data/video.mp4'); }, 'addPreview': function(name, value) {}, 'addPreviewMetadata': function(name, value) {} }; var gtMockPreviewContext = { 'contentId': gtContent.id, 'revisionId': gtRevision.revisionId, 'revision': gtRevision, 'download': function(callback) { return callback(null, __dirname + '/data/video.mp4'); }, 'addPreview': function(name, value) {}, 'addPreviewMetadata': function(name, value) {} }; // Invoke the processors, letting the mock MediaCore servers and routes we set up earlier handle the remaining assertions MediaCoreProcessor.generatePreviews(camMockPreviewContext, camContent, function(err) { assert.ok(err); MediaCoreProcessor.generatePreviews(gtMockPreviewContext, gtContent, function(err) { assert.ok(err); // Don't callback here, we're expecting the `_finishMediaCoreRequest` function to eventually call back }); }); }); }); }); }); }); }); }); }); });