Skip to content

Commit

Permalink
[fix]icl-1495 imanager节点管理例子无法访问 review by qiw
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiao-supermap committed Aug 28, 2023
1 parent ca75373 commit 81c9b3a
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 31 deletions.
32 changes: 22 additions & 10 deletions examples/leaflet/iManagerNodeManager.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@
margin-bottom: 0;
}

#listTable {
margin: 0 auto;
border: 1px solid #cfcfcf;
border-radius: 4px;
border-collapse: collapse;
border-style:hidden;
box-shadow: 0 0 0 1px #cfcfcf;
}

#listTable th, #listTable td {
padding: 5px;
border: 1px solid #cfcfcf;
}
</style>
</head>
Expand Down Expand Up @@ -51,16 +61,15 @@ <h4 data-i18n="resources.title_nodeManagementUseExample"></h4>
data-i18n="resources.text_userName"></label>

<div class="col-md-8">
<input type="text" class="form-control" id="username_iManager" value="admin">
<input type="text" class="form-control" id="username_iManager">
</div>
</div>
<div class="form-group">
<label for="password_iManager" class="col-md-2 control-label"
data-i18n="resources.text_password"></label>

<div class="col-md-8">
<input type="password" class="form-control" id="password_iManager"
value="admin">
<input type="password" class="form-control" id="password_iManager">
</div>
</div>
<div class="form-group">
Expand All @@ -87,13 +96,13 @@ <h4 data-i18n="resources.title_nodeManagementUseExample"></h4>
<table id="listTable">
<thead>
<tr role="row">
<th rowspan="1" colspan="1" style="width: 50px;">
<th rowspan="1" colspan="1" style="width: 80px;">
<div><span>id</span></div>
</th>
<th rowspan="1" colspan="1" style="width: 150px;">
<th rowspan="1" colspan="1" style="width: 200px;">
<div><span data-i18n="resources.text_name"></span></div>
</th>
<th rowspan="1" colspan="1" style="width: 150px;">
<th rowspan="1" colspan="1" style="width: 220px;">
<div><span data-i18n="resources.text_address"></span></div>
</th>
</tr>
Expand Down Expand Up @@ -216,7 +225,7 @@ <h4 data-i18n="resources.title_nodeManagementUseExample"></h4>
<script>

$(document).ready(function () {
$("#loginUrl_iManager").val("http://imgr.supermapol.com/imanager");
$("#loginUrl_iManager").val("http://localhost:8390/imanager");
});

/*登录*/
Expand All @@ -240,15 +249,18 @@ <h4 data-i18n="resources.title_nodeManagementUseExample"></h4>
.then(function (response) {
console.log(JSON.stringify(response));
var result = response;
var html = "";
if (result.list) {
var html = "";
for (var i = 0; i < result.list.length; i++) {
var obj = result.list[i];
var address = obj.productInfos ? obj.productInfos[0].address : "";
html += "<tr role='row'><td>" + obj.id + "</td><td>" + obj.nodeName + "</td><td><a href='" + address + "' target='_blank'>" + address + "</a></td><td></tr>";
html += "<tr role='row'><td>" + obj.id + "</td><td>" + obj.nodeName + "</td><td><a href='" + address + "' target='_blank'>" + address + "</a></td></tr>";
}
$("#nodeList").html(html);

} else {
html += "<tr role='row'><td></td><td></td><td></td></tr>";
}
$("#nodeList").html(html);
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/common/iManager/iManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class IManager extends IManagerServiceBase {
* @returns {Promise} Promise 对象。
*/
createIServer(createParam) {
return this.request("POST", this.serviceUrl + '/icloud/web/nodes/server.json', new IManagerCreateNodeParam(createParam));
return this.request("POST", this.serviceUrl + '/cloud/web/nodes/server.json', new IManagerCreateNodeParam(createParam));
}

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

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

/**
Expand All @@ -84,7 +84,7 @@ export class IManager extends IManagerServiceBase {
* @returns {Promise} Promise 对象。
*/
stopNodes(ids) {
return this.request("POST", this.serviceUrl + '/icloud/web/nodes/stopped.json', ids);
return this.request("POST", this.serviceUrl + '/cloud/web/nodes/stopped.json', ids);
}
}

5 changes: 1 addition & 4 deletions src/common/iManager/iManagerServiceBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ export class IManagerServiceBase {
'Content-Type': 'application/json'
}
};
if (!requestOptions.hasOwnProperty("withCredentials")) {
requestOptions['withCredentials'] = true;
}
requestOptions['crossOrigin'] = this.options.crossOrigin;
requestOptions['headers'] = this.options.headers;
var token = SecurityManager.imanagerToken;
if (token) {
if (!requestOptions.headers) {
requestOptions.headers = [];
requestOptions.headers = {};
}
requestOptions.headers['X-Auth-Token'] = token;
}
Expand Down
21 changes: 8 additions & 13 deletions src/common/security/SecurityManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class SecurityManager {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
withCredentials: true
withCredentials: false
};
return FetchRequest.post(url, loginInfo, requestOptions).then(function(response) {
return response.json();
Expand Down Expand Up @@ -247,13 +247,8 @@ export class SecurityManager {
* @param {boolean} [options.isNewTab=true] - 不同域时是否在新窗口打开登录页面。
* @returns {Promise} 包含 iManager 登录请求结果的 Promise 对象。
*/
static loginManager(url, loginInfoParams, options) {
if (!Util.isInTheSameDomain(url)) {
var isNewTab = options ? options.isNewTab : true;
this._open(url, isNewTab);
return;
}
var requestUrl = Util.urlPathAppend(url, 'icloud/security/tokens');
static loginManager(url, loginInfoParams) {
var requestUrl = Util.urlPathAppend(url, '/security/tokens');
var params = loginInfoParams || {};
var loginInfo = {
username: params.userName && params.userName.toString(),
Expand All @@ -263,15 +258,15 @@ export class SecurityManager {
var requestOptions = {
headers: {
Accept: '*/*',
'Content-Type': 'application/json'
'Content-Type': 'application/json; charset=UTF-8'
}
};
var me = this;
return FetchRequest.post(requestUrl, loginInfo, requestOptions).then(function(response) {
response.text().then(function(result) {
me.imanagerToken = result;
return result;
});
return response.text();
}).then(function(result) {
me.imanagerToken = result;
return result;
});
}

Expand Down
64 changes: 64 additions & 0 deletions test/common/iManager/iManagerSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { IManager } from '../../../src/common/IManager/IManager';
import { FetchRequest } from '../../../src/common/util/FetchRequest';
import { SecurityManager } from '../../../src/common/security/SecurityManager';

SecurityManager.imanagerToken = 'test';
describe('IManager', () => {
it('iServerList', (done) => {
var imanager = new IManager('https://fake/imanager');
expect(imanager).not.toBeNull();
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
expect(options.headers['X-Auth-Token']).toBe('test');
expect(testUrl).toBe('https://fake/imanager/cloud/web/nodes/server.json');
return Promise.resolve(new Response(`{"list":[],"total":0}`));
});
imanager.iServerList().then(function (response) {
const res = JSON.stringify(response);
expect(res).toBe('{"list":[],"total":0}');
done();
});
});
it('createIServer', (done) => {
var imanager = new IManager('https://fake/imanager');
expect(imanager).not.toBeNull();
spyOn(FetchRequest, 'post').and.callFake((testUrl, params, options) => {
expect(options.headers['X-Auth-Token']).toBe('test');
expect(testUrl).toBe('https://fake/imanager/cloud/web/nodes/server.json');
return Promise.resolve(new Response(`{"isSucceed":true}`));
});
imanager.createIServer({}).then(function (response) {
const res = JSON.stringify(response);
expect(res).toBe('{"isSucceed":true}');
done();
});
});
it('startNodes', (done) => {
var imanager = new IManager('https://fake/imanager');
expect(imanager).not.toBeNull();
spyOn(FetchRequest, 'post').and.callFake((testUrl, params, options) => {
expect(options.headers['X-Auth-Token']).toBe('test');
expect(testUrl).toBe('https://fake/imanager/cloud/web/nodes/started.json');
return Promise.resolve(new Response(`{"isSucceed":true}`));
});
imanager.startNodes([1]).then(function (response) {
const res = JSON.stringify(response);
expect(res).toBe('{"isSucceed":true}');
done();
});
});
it('stopNodes', (done) => {
SecurityManager.imanagerToken = 'test';
var imanager = new IManager('https://fake/imanager');
expect(imanager).not.toBeNull();
spyOn(FetchRequest, 'post').and.callFake((testUrl, params, options) => {
expect(options.headers['X-Auth-Token']).toBe('test');
expect(testUrl).toBe('https://fake/imanager/cloud/web/nodes/stopped.json');
return Promise.resolve(new Response(`{"isSucceed":true}`));
});
imanager.stopNodes([1]).then(function (response) {
const res = JSON.stringify(response);
expect(res).toBe('{"isSucceed":true}');
done();
});
});
});
12 changes: 12 additions & 0 deletions test/common/security/SecurityManagerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ describe('SecurityManager', () => {
SecurityManager.loginiPortal(url, 'admin', 'admin');
});

it('loginManager', () => {
spyOn(FetchRequest, 'post').and.callFake((testUrl, params, options) => {
expect(testUrl).toBe("http://fakeimanager/imanager/security/tokens");
expect(params).not.toBeNull();
return Promise.resolve(new Response(`test`));
});
var url = 'http://fakeimanager/imanager';
SecurityManager.loginManager(url, 'admin', 'admin').then(res => {
expect(res).toBe('test');
})
});

it('destroyAllCredentials', () => {
SecurityManager.destroyAllCredentials();
expect(SecurityManager.keys).toBeNull();
Expand Down
1 change: 1 addition & 0 deletions test/test-main-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ import './common/online/OnlineSpec.js';
import './common/online/OnlineQueryDatasParameterSpec';

/**common -- iManager**/
import './common/iManager/iManagerSpec.js';
import './common/iManager/iManagerCreateNodeParamSpec.js';

/**common -- iPortal**/
Expand Down

0 comments on commit 81c9b3a

Please sign in to comment.