Skip to content

Commit 994dd0d

Browse files
[fix]icl-1495 imanager节点管理例子无法访问 review by qiw
1 parent 13ab848 commit 994dd0d

File tree

7 files changed

+93
-25
lines changed

7 files changed

+93
-25
lines changed

examples/leaflet/iManagerNodeManager.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,15 @@ <h4 data-i18n="resources.title_nodeManagementUseExample"></h4>
5151
data-i18n="resources.text_userName"></label>
5252

5353
<div class="col-md-8">
54-
<input type="text" class="form-control" id="username_iManager" value="admin">
54+
<input type="text" class="form-control" id="username_iManager">
5555
</div>
5656
</div>
5757
<div class="form-group">
5858
<label for="password_iManager" class="col-md-2 control-label"
5959
data-i18n="resources.text_password"></label>
6060

6161
<div class="col-md-8">
62-
<input type="password" class="form-control" id="password_iManager"
63-
value="admin">
62+
<input type="password" class="form-control" id="password_iManager">
6463
</div>
6564
</div>
6665
<div class="form-group">
@@ -216,7 +215,7 @@ <h4 data-i18n="resources.title_nodeManagementUseExample"></h4>
216215
<script>
217216

218217
$(document).ready(function () {
219-
$("#loginUrl_iManager").val("http://imgr.supermapol.com/imanager");
218+
$("#loginUrl_iManager").val("http://localhost:8090/imanager");
220219
});
221220

222221
/*登录*/

src/common/iManager/iManager.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class IManager extends IManagerServiceBase {
3636
* @returns {Promise} Promise 对象。
3737
*/
3838
createIServer(createParam) {
39-
return this.request("POST", this.serviceUrl + '/icloud/web/nodes/server.json', new IManagerCreateNodeParam(createParam));
39+
return this.request("POST", this.serviceUrl + '/cloud/web/nodes/server.json', new IManagerCreateNodeParam(createParam));
4040
}
4141

4242
/**
@@ -55,7 +55,7 @@ export class IManager extends IManagerServiceBase {
5555
* @returns {Promise} Promise 对象。
5656
*/
5757
iServerList() {
58-
return this.request("GET", this.serviceUrl + '/icloud/web/nodes/server.json');
58+
return this.request("GET", this.serviceUrl + '/cloud/web/nodes/server.json');
5959
}
6060

6161
/**
@@ -74,7 +74,7 @@ export class IManager extends IManagerServiceBase {
7474
* @returns {Promise} Promise 对象。
7575
*/
7676
startNodes(ids) {
77-
return this.request("POST", this.serviceUrl + '/icloud/web/nodes/started.json', ids);
77+
return this.request("POST", this.serviceUrl + '/cloud/web/nodes/started.json', ids);
7878
}
7979

8080
/**
@@ -84,7 +84,7 @@ export class IManager extends IManagerServiceBase {
8484
* @returns {Promise} Promise 对象。
8585
*/
8686
stopNodes(ids) {
87-
return this.request("POST", this.serviceUrl + '/icloud/web/nodes/stopped.json', ids);
87+
return this.request("POST", this.serviceUrl + '/cloud/web/nodes/stopped.json', ids);
8888
}
8989
}
9090

src/common/iManager/iManagerServiceBase.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,12 @@ export class IManagerServiceBase {
4444
'Content-Type': 'application/json'
4545
}
4646
};
47-
if (!requestOptions.hasOwnProperty("withCredentials")) {
48-
requestOptions['withCredentials'] = true;
49-
}
5047
requestOptions['crossOrigin'] = this.options.crossOrigin;
5148
requestOptions['headers'] = this.options.headers;
5249
var token = SecurityManager.imanagerToken;
5350
if (token) {
5451
if (!requestOptions.headers) {
55-
requestOptions.headers = [];
52+
requestOptions.headers = {};
5653
}
5754
requestOptions.headers['X-Auth-Token'] = token;
5855
}

src/common/security/SecurityManager.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class SecurityManager {
205205
headers: {
206206
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
207207
},
208-
withCredentials: true
208+
withCredentials: false
209209
};
210210
return FetchRequest.post(url, loginInfo, requestOptions).then(function(response) {
211211
return response.json();
@@ -247,13 +247,8 @@ export class SecurityManager {
247247
* @param {boolean} [options.isNewTab=true] - 不同域时是否在新窗口打开登录页面。
248248
* @returns {Promise} 包含 iManager 登录请求结果的 Promise 对象。
249249
*/
250-
static loginManager(url, loginInfoParams, options) {
251-
if (!Util.isInTheSameDomain(url)) {
252-
var isNewTab = options ? options.isNewTab : true;
253-
this._open(url, isNewTab);
254-
return;
255-
}
256-
var requestUrl = Util.urlPathAppend(url, 'icloud/security/tokens');
250+
static loginManager(url, loginInfoParams) {
251+
var requestUrl = Util.urlPathAppend(url, '/security/tokens');
257252
var params = loginInfoParams || {};
258253
var loginInfo = {
259254
username: params.userName && params.userName.toString(),
@@ -263,15 +258,15 @@ export class SecurityManager {
263258
var requestOptions = {
264259
headers: {
265260
Accept: '*/*',
266-
'Content-Type': 'application/json'
261+
'Content-Type': 'application/json; charset=UTF-8'
267262
}
268263
};
269264
var me = this;
270265
return FetchRequest.post(requestUrl, loginInfo, requestOptions).then(function(response) {
271-
response.text().then(function(result) {
272-
me.imanagerToken = result;
273-
return result;
274-
});
266+
return response.text();
267+
}).then(function(result) {
268+
me.imanagerToken = result;
269+
return result;
275270
});
276271
}
277272

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { IManager } from '../../../src/common/IManager/IManager';
2+
import { FetchRequest } from '../../../src/common/util/FetchRequest';
3+
import { SecurityManager } from '../../../src/common/security/SecurityManager';
4+
5+
SecurityManager.imanagerToken = 'test';
6+
describe('IManager', () => {
7+
it('iServerList', (done) => {
8+
var imanager = new IManager('https://fake/imanager');
9+
expect(imanager).not.toBeNull();
10+
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
11+
expect(options.headers['X-Auth-Token']).toBe('test');
12+
expect(testUrl).toBe('https://fake/imanager/cloud/web/nodes/server.json');
13+
return Promise.resolve(new Response(`{"list":[],"total":0}`));
14+
});
15+
imanager.iServerList().then(function (response) {
16+
const res = JSON.stringify(response);
17+
expect(res).toBe('{"list":[],"total":0}');
18+
done();
19+
});
20+
});
21+
it('createIServer', (done) => {
22+
var imanager = new IManager('https://fake/imanager');
23+
expect(imanager).not.toBeNull();
24+
spyOn(FetchRequest, 'post').and.callFake((testUrl, params, options) => {
25+
expect(options.headers['X-Auth-Token']).toBe('test');
26+
expect(testUrl).toBe('https://fake/imanager/cloud/web/nodes/server.json');
27+
return Promise.resolve(new Response(`{"isSucceed":true}`));
28+
});
29+
imanager.createIServer({}).then(function (response) {
30+
const res = JSON.stringify(response);
31+
expect(res).toBe('{"isSucceed":true}');
32+
done();
33+
});
34+
});
35+
it('startNodes', (done) => {
36+
var imanager = new IManager('https://fake/imanager');
37+
expect(imanager).not.toBeNull();
38+
spyOn(FetchRequest, 'post').and.callFake((testUrl, params, options) => {
39+
expect(options.headers['X-Auth-Token']).toBe('test');
40+
expect(testUrl).toBe('https://fake/imanager/cloud/web/nodes/started.json');
41+
return Promise.resolve(new Response(`{"isSucceed":true}`));
42+
});
43+
imanager.startNodes([1]).then(function (response) {
44+
const res = JSON.stringify(response);
45+
expect(res).toBe('{"isSucceed":true}');
46+
done();
47+
});
48+
});
49+
it('stopNodes', (done) => {
50+
SecurityManager.imanagerToken = 'test';
51+
var imanager = new IManager('https://fake/imanager');
52+
expect(imanager).not.toBeNull();
53+
spyOn(FetchRequest, 'post').and.callFake((testUrl, params, options) => {
54+
expect(options.headers['X-Auth-Token']).toBe('test');
55+
expect(testUrl).toBe('https://fake/imanager/cloud/web/nodes/stopped.json');
56+
return Promise.resolve(new Response(`{"isSucceed":true}`));
57+
});
58+
imanager.stopNodes([1]).then(function (response) {
59+
const res = JSON.stringify(response);
60+
expect(res).toBe('{"isSucceed":true}');
61+
done();
62+
});
63+
});
64+
});

test/common/security/SecurityManagerSpec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ describe('SecurityManager', () => {
9898
SecurityManager.loginiPortal(url, 'admin', 'admin');
9999
});
100100

101+
it('loginManager', () => {
102+
spyOn(FetchRequest, 'post').and.callFake((testUrl, params, options) => {
103+
expect(testUrl).toBe("http://fakeimanager/imanager/security/tokens");
104+
expect(params).not.toBeNull();
105+
return Promise.resolve(new Response(`test`));
106+
});
107+
var url = 'http://fakeimanager/imanager';
108+
SecurityManager.loginManager(url, 'admin', 'admin').then(res => {
109+
expect(res).toBe('test');
110+
})
111+
});
112+
101113
it('destroyAllCredentials', () => {
102114
SecurityManager.destroyAllCredentials();
103115
expect(SecurityManager.keys).toBeNull();

test/test-main-common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ import './common/online/OnlineSpec.js';
180180
import './common/online/OnlineQueryDatasParameterSpec';
181181

182182
/**common -- iManager**/
183+
import './common/iManager/iManagerSpec.js';
183184
import './common/iManager/iManagerCreateNodeParamSpec.js';
184185

185186
/**common -- iPortal**/

0 commit comments

Comments
 (0)