-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Extensions] ExtensionAdmin registerHost should accept hostnames and …
…urls (#3631) * ExtensionAdmin should accept hostnames and urls * Remove the "_exists" method from the remote and extension service providers * make iTwinId default to public on Service Extensions * remove any cast and just log the error msg as is * remove 'ftp' since its something we don't expect as input * documentation fixes * ServiceExtension props should not require a version - defaults to the latest * attempt to parse the text response if body is null (happened during testing) (cherry picked from commit 9b3ac9b)
- Loading branch information
1 parent
34d6e2e
commit 1ccfddf
Showing
7 changed files
with
141 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
common/changes/@itwin/core-frontend/extensions-register-hostnames_2022-05-17-15-42.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@itwin/core-frontend", | ||
"comment": "", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@itwin/core-frontend" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import chai, { expect } from "chai"; | ||
import { ExtensionManifest, RemoteExtensionProvider } from "../core-frontend"; | ||
import { ExtensionAdmin } from "../extension/ExtensionAdmin"; | ||
import chaiAsPromised from "chai-as-promised"; | ||
import sinon from "sinon"; | ||
|
||
describe("ExtensionAdmin", () => { | ||
const extensions = [ | ||
new RemoteExtensionProvider({ | ||
jsUrl: "http://localhost:3000/index.js", | ||
manifestUrl: "http://localhost:3000/package.json", | ||
}), | ||
new RemoteExtensionProvider({ | ||
jsUrl: "https://somedomain:3001/index.js", | ||
manifestUrl: "https://somedomain:3001/package.json", | ||
}), | ||
new RemoteExtensionProvider({ | ||
jsUrl: "https://anotherdomain.com/index.js", | ||
manifestUrl: "https://anotherdomain.com/package.json", | ||
}), | ||
]; | ||
const stubManifest: Promise<ExtensionManifest> = new Promise((res) => res({ | ||
name: "mock-extension", | ||
version: "1.0.0", | ||
main: "index.js", | ||
activationEvents: [], | ||
})); | ||
|
||
before(async () => { | ||
chai.use(chaiAsPromised); | ||
sinon.stub(RemoteExtensionProvider.prototype, "getManifest").returns(stubManifest); | ||
}); | ||
|
||
it("ExtensionAdmin can register a url", async () => { | ||
const extensionAdmin = new ExtensionAdmin(); | ||
extensionAdmin.registerHost(extensions[0].hostname); | ||
extensionAdmin.registerHost("https://somedomain:3001"); | ||
extensionAdmin.registerHost("https://anotherdomain.com/dist/index.js"); | ||
for (const extension of extensions) { | ||
await expect(extensionAdmin.addExtension(extension)).to.eventually.be.fulfilled; | ||
} | ||
}); | ||
|
||
it("ExtensionAdmin can register a hostname", async () => { | ||
const extensionAdmin = new ExtensionAdmin(); | ||
extensionAdmin.registerHost(extensions[0].hostname); | ||
extensionAdmin.registerHost("www.somedomain"); | ||
extensionAdmin.registerHost("anotherdomain.com"); | ||
|
||
for (const extension of extensions) { | ||
await expect(extensionAdmin.addExtension(extension)).to.eventually.be.fulfilled; | ||
} | ||
}); | ||
|
||
it("ExtensionAdmin will fail if remote extension hostname was not registered", async () => { | ||
const extensionAdmin = new ExtensionAdmin(); | ||
extensionAdmin.registerHost("aDifferentHostname"); | ||
for (const extension of extensions) { | ||
await expect(extensionAdmin.addExtension(extension)).to.eventually.be.rejectedWith(/not registered/); | ||
} | ||
}); | ||
|
||
it("ExtensionAdmin will reject invalid URLs or hostnames", () => { | ||
const extensionAdmin = new ExtensionAdmin(); | ||
expect(() => extensionAdmin.registerHost("3001:invalidUrl")).to.throw(/should be a valid URL or hostname/); | ||
expect(() => extensionAdmin.registerHost("invalidUrl342!@#")).to.throw(/should be a valid URL or hostname/); | ||
}); | ||
}); |