Skip to content
Snippets Groups Projects
Unverified Commit d15f5342 authored by Tom Robinson's avatar Tom Robinson Committed by GitHub
Browse files

Fix premium embedding token settings (#12281)


* Add cypress test for embedding settings

* Yarn pretty

* Import metabase.public-settings.metastore. Resolves #12273

* lint

* Fix lint

Co-authored-by: default avatarDamon P. Cortesi <d.lifehacker@gmail.com>
parent 275fd836
No related branches found
No related tags found
No related merge requests found
......@@ -109,6 +109,7 @@ export default class SettingsEditorApp extends Component {
const { settings, updateSetting } = this.props;
const setting = _.findWhere(settings, { key });
if (!setting) {
console.error(`Attempted to change unknown setting ${key}`);
throw new Error(t`Unknown setting ${key}`);
}
return updateSetting({ ...setting, value });
......
......@@ -60,6 +60,95 @@ describe("scenarios > admin > settings", () => {
cy.contains(/^February 11, 2019, 9:40 PM$/);
});
describe(" > embedding settings", () => {
it("should validate a premium embedding token has a valid format", () => {
cy.server();
cy.route("PUT", "/api/setting/premium-embedding-token").as(
"saveEmbeddingToken",
);
cy.visit("/admin/settings/embedding_in_other_applications");
cy.contains("Premium embedding");
cy.contains("Enter a token").click();
// Try an invalid token format
cy.contains("Enter the token")
.next()
.type("Hi")
.blur();
cy.wait("@saveEmbeddingToken").then(({ response }) => {
expect(response.body).to.equal(
"Token format is invalid. Token should be 64 hexadecimal characters.",
);
});
cy.contains("Token format is invalid.");
});
it("should validate a premium embedding token exists", () => {
cy.server();
cy.route("PUT", "/api/setting/premium-embedding-token").as(
"saveEmbeddingToken",
);
cy.visit("/admin/settings/embedding_in_other_applications");
cy.contains("Premium embedding");
cy.contains("Enter a token").click();
// Try a valid format, but an invalid token
cy.contains("Enter the token")
.next()
.type(
"11397b1e60cfb1372f2f33ac8af234a15faee492bbf5c04d0edbad76da3e614a",
)
.blur();
cy.wait("@saveEmbeddingToken").then(({ response }) => {
expect(response.body).to.equal(
"Unable to validate token: 404 not found.",
);
});
cy.contains("Unable to validate token: 404 not found.");
});
it("should be able to set a premium embedding token", () => {
// A random embedding token with valid format
const embeddingToken =
"11397b1e60cfb1372f2f33ac8af234a15faee492bbf5c04d0edbad76da3e614a";
cy.server();
cy.route({
method: "PUT",
url: "/api/setting/premium-embedding-token",
response: embeddingToken,
}).as("saveEmbeddingToken");
cy.visit("/admin/settings/embedding_in_other_applications");
cy.contains("Premium embedding");
cy.contains("Enter a token").click();
cy.route("GET", "/api/session/properties").as("getSessionProperties");
cy.route({
method: "GET",
url: "/api/setting",
response: [
{ key: "enable-embedding", value: true },
{ key: "embedding-secret-key", value: embeddingToken },
{ key: "premium-embedding-token", value: embeddingToken },
],
}).as("getSettings");
cy.contains("Enter the token")
.next()
.type(embeddingToken)
.blur();
cy.wait("@saveEmbeddingToken").then(({ response }) => {
expect(response.body).to.equal(embeddingToken);
});
cy.wait("@getSessionProperties");
cy.wait("@getSettings");
cy.contains("Premium embedding enabled");
});
});
describe(" > email settings", () => {
it("should be able to save email settings", () => {
cy.visit("/admin/settings/email");
......
......@@ -10,12 +10,16 @@
[metabase.models
[common :as common]
[setting :as setting :refer [defsetting]]]
metabase.public-settings.metastore
[metabase.util
[i18n :refer [available-locales-with-names deferred-tru set-locale trs tru]]
[password :as password]]
[toucan.db :as db])
(:import java.util.UUID))
;; These modules register settings but are otherwise unused. They still must be imported.
(comment metabase.public-settings.metastore/keep-me)
(defsetting check-for-updates
(deferred-tru "Identify when new versions of Metabase are available.")
:type :boolean
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment