Skip to content

Commit fd502ea

Browse files
committed
JBDS-3990 Create mock server to test online installer
1. http/https servers implemented. both required, because we have http and https redirects in reequirements.json; 2. account/controller.js using request module to check T&C's instead of angular http services, to be able to force ignore self signed sertificate for mock https server; 3. self signed sertificate error ignored by setting env variable DSI_REJECT_UNAUTHORIZED=false; 4. developers.redhat.com mapped to localhost in hosts file in c:\Windows\system32\drivers\etc\hosts; 5. gulp prefetch-all task added to download all binaries before running mock serveres; 6. Run servers using node gulp-tasks/http(s)-server.js 7. Documentation updated
1 parent 957641a commit fd502ea

13 files changed

Lines changed: 276 additions & 55 deletions

File tree

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ of any test, e.g.:
9292
npm test -- -g login
9393
npm test -- --grep login
9494

95+
96+
Running Angular protractor UI tests
97+
---------------------------
98+
99+
UI tests are located in 'test/ui'. To run all UI tests:
100+
101+
npm ui-test
102+
95103
Debugging
96104
---------
97105

@@ -102,10 +110,43 @@ Enable ChromeDevtools in installer window
102110

103111
or you can run installer with
104112

105-
npm run
113+
npm run
106114

107115
and then push Ctrl + Shift + I to show ChromDevTools in current installer window
108116

117+
Testing online installer
118+
------------------------
119+
120+
In windows System Properties Setting Dialog add
121+
122+
DSI_REJECT_UNAUTHORIZED=false
123+
124+
to your user environment variables.
125+
Run notepad.exe as Administrator and add
126+
127+
127.0.0.1 developers.redhat.com
128+
129+
to C:\Windows\system32\Drivers\etec\hosts file.
130+
131+
Then download (VPN is Required) all requirements with
132+
133+
gulp prefetch-all
134+
135+
When download is finished run http and https mock servers to mimic
136+
developers.redhat.com with download-manager links. In separate windows run
137+
138+
node gulp-tasks/http-server.js
139+
140+
and Then
141+
142+
node gulp-tasks/https-server.js
143+
144+
Now you are ready to test online installer. Start
145+
dist/win/DevelopmentSuiteInstaller-win32-x64-*.exe from package explorer. Mock
146+
http server always returns let you pass account information page, but if you
147+
plan to install and test CDK in DevStudio use your real Red Hat user name from
148+
developers.rdhat.com.
149+
109150
Releasing the installer
110151
-----------------------
111152

browser/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import pathValidator from './directives/pathValidator';
1313
import progressBar from './directives/progressBar';
1414
import breadcrumb from './directives/breadcrumb';
1515
import InstallerDataService from './services/data';
16+
import Request from './services/request';
1617
import VirtualBoxInstall from './model/virtualbox';
1718
import JdkInstall from './model/jdk-install';
1819
import JbdsInstall from './model/jbds';
@@ -29,6 +30,7 @@ let mainModule =
2930
.controller(instCtrl.name, instCtrl)
3031
.controller(startCtrl.name, startCtrl)
3132
.factory('installerDataSvc', InstallerDataService.factory)
33+
.factory('request', Request.factory)
3234
.directive(progressBar.name, progressBar)
3335
.directive(breadcrumb.name, ['$state', breadcrumb])
3436
.directive(pathValidator.name, pathValidator)
@@ -74,7 +76,7 @@ let mainModule =
7476
}
7577
});
7678
}])
77-
.run( ['$rootScope', '$location', '$timeout', 'installerDataSvc', ($rootScope, $location, $timeout, installerDataSvc) => {
79+
.run( ['$rootScope', '$location', '$timeout', 'installerDataSvc', 'request', ($rootScope, $location, $timeout, installerDataSvc, request) => {
7880
let reqs = Util.resolveFile('.', 'requirements.json');
7981

8082
let virtualbox = new VirtualBoxInstall(

browser/model/cdk.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ class CDKInstall extends InstallableItem {
195195
});
196196
},(result)=>{
197197
return installer.exec('vagrant box add --name cdkv2 ' + this.boxName , opts, result);
198-
},(result)=>{
199-
return installer.exec('vagrant plugin install landrush', opts);
200198
});
201199
return Util.runPromiseSequence(execs);
202200
}

browser/model/helpers/downloader.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ let fs = require('fs-extra');
55

66
import Hash from './hash';
77
import Logger from '../../services/logger';
8+
import Util from './util';
89
const remote = require('electron').remote;
910

1011
class Downloader {
@@ -79,29 +80,6 @@ class Downloader {
7980
this.failure('SHA256 checksum verification failed');
8081
}
8182
});
82-
} else if(url && url.includes("?workflow=direct")) {
83-
let shaUrl = url.replace("?workflow=direct",".sha256");
84-
Logger.log(`Downloading sha256 from ${shaUrl}`);
85-
request(this.setAdditionalOptions(shaUrl), (error, response, sha) => {
86-
if (!error && response.statusCode == 200) {
87-
Logger.log(`Downloaded sha256='${sha}'`);
88-
if(sha) {
89-
var h = new Hash();
90-
h.SHA256(file,(dlSha) => {
91-
Logger.log(`Downloaded file='${file}' sha256='${dlSha}'`);
92-
if(sha === dlSha) {
93-
this.successHandler(file);
94-
} else {
95-
this.downloads.get(file)['failure'] = true;
96-
this.failure(`Dowloaded file sha256 '${dlSha}' doesn't match sha256 '${sha}' from ${shaUrl}`);
97-
}
98-
});
99-
}
100-
} else {
101-
this.downloads.get(file)['failure'] = true;
102-
this.failure(`SHA256 checksum filr download from ${shaUrl} failed with ${error}`);
103-
}
104-
});
10583
} else {
10684
this.successHandler(file);
10785
}
@@ -125,7 +103,7 @@ class Downloader {
125103
.on('data', this.dataHandler.bind(this))
126104
.on('end', this.endHandler.bind(this, stream))
127105
.pipe(stream)
128-
.on('close', this.closeHandler.bind(this,stream.path,sha,options));
106+
.on('finish', this.closeHandler.bind(this,stream.path,sha,options));
129107
}
130108

131109
downloadAuth(options, username, password, file, sha) {
@@ -138,9 +116,11 @@ class Downloader {
138116
.on('data', this.dataHandler.bind(this))
139117
.on('end', this.endHandler.bind(this, stream))
140118
.pipe(stream)
141-
.on('close', this.closeHandler.bind(this,stream.path,sha,options));
119+
.on('finish', this.closeHandler.bind(this,stream.path,sha,options));
142120
}
143121

122+
123+
144124
restartDownload() {
145125
this.downloadSize = 0;
146126
this.received = 0;
@@ -172,6 +152,7 @@ class Downloader {
172152
};
173153
optionsObj['followAllRedirects'] = true;
174154
optionsObj['jar'] = request.jar();
155+
optionsObj['rejectUnauthorized'] = Util.getRejectUnauthorized();
175156
return optionsObj;
176157
}
177158
}

browser/model/helpers/util.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ class Util {
105105

106106
return reqs;
107107
}
108+
109+
static getRejectUnauthorized() {
110+
let value = process.env['DSI_REJECT_UNAUTHORIZED'];
111+
let result = true;
112+
try {
113+
result = JSON.parse(value);
114+
} catch (error) {
115+
}
116+
return result;
117+
}
108118
}
109119

110120
export default Util;

browser/pages/account/controller.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
'use strict';
22

33
import Util from '../../model/helpers/util';
4-
4+
const remote = require('electron').remote;
55
const shell = require('electron').shell;
66
let pjson = Util.resolveFile('.', 'package.json');
77

88
class AccountController {
99

10-
constructor($state, $http, $base64, installerDataSvc) {
10+
constructor($state, $timeout, $scope, request, $base64, installerDataSvc) {
1111
this.router = $state;
12-
this.http = $http;
12+
this.http = request;
1313
this.base64 = $base64;
14+
this.timeout = $timeout;
15+
this.scope = $scope;
1416
this.installerDataSvc = installerDataSvc;
1517

1618
this.username = "";
@@ -27,18 +29,29 @@ class AccountController {
2729

2830
let req = {
2931
method: 'GET',
30-
url: 'https://developers.redhat.com/download-manager/rest/tc-accepted?downloadURL=/file/cdk-2.0.0-beta3.zip',
32+
url: 'https://developers.redhat.com/download-manager/rest/tc-accepted?downloadURL=/file/cdk-2.1.0.zip',
33+
auth: {
34+
user: this.username,
35+
pass: this.password,
36+
sendImmediately: true
37+
},
3138
headers: {
32-
'Authorization': 'Basic ' + this.base64.encode(this.username + ':' + this.password)
39+
'Accept' : 'application/json, text/plain, */*',
40+
'User-Agent': this.getUserAgent()
3341
},
34-
responseType: 'text'
42+
followAllRedirects: true,
43+
rejectUnauthorized: Util.getRejectUnauthorized()
3544
};
3645

3746
this.http(req)
3847
.then(this.handleHttpSuccess.bind(this))
3948
.catch(this.handleHttpFailure.bind(this));
4049
}
4150

51+
getUserAgent() {
52+
return remote.getCurrentWindow().webContents.session.getUserAgent();
53+
}
54+
4255
forgotPassword() {
4356
shell.openExternal('https://developers.redhat.com/auth/realms/rhd/account');
4457
}
@@ -65,14 +78,22 @@ class AccountController {
6578
}
6679
}
6780
this.authFailed = true;
81+
this.apply();
6882
}
6983

7084
handleHttpFailure() {
7185
this.authFailed = true;
7286
this.isLoginBtnClicked = false;
87+
this.apply();
88+
}
89+
90+
apply() {
91+
this.timeout(()=>{
92+
this.scope.$apply();
93+
});
7394
}
7495
}
7596

76-
AccountController.$inject = ['$state', '$http', '$base64', 'installerDataSvc'];
97+
AccountController.$inject = ['$state', '$timeout', '$scope', 'request', '$base64', 'installerDataSvc'];
7798

7899
export default AccountController;

browser/services/request.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
let request = require('request');
4+
5+
class Request {
6+
constructor(){
7+
}
8+
9+
get(req) {
10+
return new Promise((resolve,reject)=>{
11+
request(req, (error, response, data) => {
12+
if (!error && response.statusCode == 200) {
13+
resolve({
14+
status: response.statusCode,
15+
data: JSON.parse(data)
16+
});
17+
} else {
18+
reject();
19+
}
20+
});
21+
});
22+
}
23+
24+
static factory() {
25+
return function(req) {
26+
return new Request().get(req);
27+
};
28+
}
29+
}
30+
31+
Request.factory.$inject=[];
32+
33+
export default Request;

gulp-tasks/http-server.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//Lets require/import the HTTP module
2+
var http = require('http');
3+
var fs = require('fs');
4+
var path = require('path');
5+
6+
//Lets define a port we want to listen to
7+
const PORT=80;
8+
9+
//We need a function which handles requests and send response
10+
function handleRequest(request, res){
11+
let file = fs.readFileSync(path.join(__dirname,"..","requirements-cache",'virtualbox.exe'));
12+
console.log("Sending file VirtualBox.exe");
13+
res.writeHead(200, {
14+
'Content-Type': 'application/x-msdownload',
15+
'Content-Disposition': `inline; filename=virtual.box`});
16+
res.write(file, 'binary');
17+
res.end();
18+
}
19+
20+
//Create a server
21+
var server = http.createServer(handleRequest);
22+
23+
//Lets start our server
24+
server.listen(PORT, function(){
25+
//Callback triggered when server is successfully listening. Hurray!
26+
console.log("Server listening on: http://localhost:%s", PORT);
27+
});

0 commit comments

Comments
 (0)