Skip to content

Commit

Permalink
Add domain restriction (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
HughParry authored Nov 6, 2024
1 parent a53540d commit a2aa975
Show file tree
Hide file tree
Showing 52 changed files with 23,078 additions and 22,365 deletions.
13 changes: 12 additions & 1 deletion demos/cypress-shared/cypress/e2e/captcha.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import { u8aToHex } from "@polkadot/util";
import { ProsopoDatasetError } from "@prosopo/common";
import { getPairAsync } from "@prosopo/contract";
import { datasetWithSolutionHashes } from "@prosopo/datasets";
import { AdminApiPaths, type Captcha } from "@prosopo/types";
import {
AdminApiPaths,
type Captcha,
type IUserSettings,
} from "@prosopo/types";
import { at } from "@prosopo/util";
import { checkboxClass } from "../support/commands.js";

Expand All @@ -27,6 +31,12 @@ describe("Captchas", () => {
const pair = await getPairAsync(Cypress.env("PROSOPO_PROVIDER_MNEMONIC"));
const signature = u8aToHex(pair.sign(timestamp.toString()));
const adminSiteKeyURL = `http://localhost:9229${AdminApiPaths.SiteKeyRegister}`;
const settings: IUserSettings = {
captchaType: "pow",
domains: ["0.0.0.0"],
frictionlessThreshold: 0.5,
powDifficulty: 2,
};
await fetch(adminSiteKeyURL, {
method: "POST",
headers: {
Expand All @@ -36,6 +46,7 @@ describe("Captchas", () => {
},
body: JSON.stringify({
siteKey: Cypress.env("PROSOPO_SITE_KEY"),
settings,
}),
});
});
Expand Down
13 changes: 12 additions & 1 deletion demos/cypress-shared/cypress/e2e/correct.captcha.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import { u8aToHex } from "@polkadot/util";
import { ProsopoDatasetError } from "@prosopo/common";
import { getPairAsync } from "@prosopo/contract";
import { datasetWithSolutionHashes } from "@prosopo/datasets";
import { AdminApiPaths, type Captcha } from "@prosopo/types";
import {
AdminApiPaths,
type Captcha,
type IUserSettings,
} from "@prosopo/types";
import { checkboxClass } from "../support/commands.js";

describe("Captchas", () => {
Expand All @@ -26,6 +30,12 @@ describe("Captchas", () => {
const pair = await getPairAsync(Cypress.env("PROSOPO_PROVIDER_MNEMONIC"));
const signature = u8aToHex(pair.sign(timestamp.toString()));
const adminSiteKeyURL = `http://localhost:9229${AdminApiPaths.SiteKeyRegister}`;
const settings: IUserSettings = {
captchaType: "pow",
domains: ["0.0.0.0"],
frictionlessThreshold: 0.5,
powDifficulty: 2,
};
await fetch(adminSiteKeyURL, {
method: "POST",
headers: {
Expand All @@ -35,6 +45,7 @@ describe("Captchas", () => {
},
body: JSON.stringify({
siteKey: Cypress.env("PROSOPO_SITE_KEY"),
settings,
}),
});
});
Expand Down
13 changes: 12 additions & 1 deletion demos/cypress-shared/cypress/e2e/correct.captcha.signup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import { u8aToHex } from "@polkadot/util";
import { ProsopoDatasetError } from "@prosopo/common";
import { getPairAsync } from "@prosopo/contract";
import { datasetWithSolutionHashes } from "@prosopo/datasets";
import { AdminApiPaths, type Captcha } from "@prosopo/types";
import {
AdminApiPaths,
type Captcha,
type IUserSettings,
} from "@prosopo/types";
import { checkboxClass } from "../support/commands.js";

describe("Captchas", () => {
Expand All @@ -26,6 +30,12 @@ describe("Captchas", () => {
const pair = await getPairAsync(Cypress.env("PROSOPO_PROVIDER_MNEMONIC"));
const signature = u8aToHex(pair.sign(timestamp.toString()));
const adminSiteKeyURL = `http://localhost:9229${AdminApiPaths.SiteKeyRegister}`;
const settings: IUserSettings = {
captchaType: "pow",
domains: ["0.0.0.0"],
frictionlessThreshold: 0.5,
powDifficulty: 2,
};
await fetch(adminSiteKeyURL, {
method: "POST",
headers: {
Expand All @@ -35,6 +45,7 @@ describe("Captchas", () => {
},
body: JSON.stringify({
siteKey: Cypress.env("PROSOPO_SITE_KEY"),
settings,
}),
});
});
Expand Down
8 changes: 6 additions & 2 deletions demos/cypress-shared/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ declare global {

export const checkboxClass = '[type="checkbox"]';
function clickIAmHuman(): Cypress.Chainable<Captcha[]> {
cy.intercept("GET", "**/prosopo/provider/captcha/**").as("getCaptcha");
cy.intercept("POST", "**/prosopo/provider/client/captcha/**").as(
"getCaptcha",
);
cy.get(checkboxClass, { timeout: 12000 }).first().click();

return cy
Expand Down Expand Up @@ -131,7 +133,9 @@ function clickCorrectCaptchaImages(
}

function clickNextButton() {
cy.intercept("POST", "**/prosopo/provider/solution").as("postSolution");
cy.intercept("POST", "**/prosopo/provider/client/solution").as(
"postSolution",
);
// Go to the next captcha or submit solution
cy.get('button[data-cy="button-next"]').click({ force: true });
cy.wait(0);
Expand Down
4 changes: 3 additions & 1 deletion dev/scripts/env.development
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL=
WATCHTOWER_NOTIFICATIONS=
WATCHTOWER_POLL_INTERVAL=30
WATCHTOWER_REMOVE_VOLUMES=true

PROSOPO_ADMIN_ADDRESS=5EjTA28bKSbFPPyMbUjNtArxyqjwq38r1BapVmLZShaqEedV
PROSOPO_ADMIN_JSON=
PROSOPO_ADMIN_MNEMONIC=puppy cream effort carbon despair leg pyramid cotton endorse immense drill peasant
3 changes: 3 additions & 0 deletions dev/scripts/env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL=
WATCHTOWER_NOTIFICATIONS=
WATCHTOWER_POLL_INTERVAL=30
WATCHTOWER_REMOVE_VOLUMES=true
PROSOPO_ADMIN_ADDRESS=5EjTA28bKSbFPPyMbUjNtArxyqjwq38r1BapVmLZShaqEedV
PROSOPO_ADMIN_JSON=
PROSOPO_ADMIN_MNEMONIC=puppy cream effort carbon despair leg pyramid cotton endorse immense drill peasant
3 changes: 3 additions & 0 deletions dev/scripts/env.test
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL=
WATCHTOWER_NOTIFICATIONS=
WATCHTOWER_POLL_INTERVAL=30
WATCHTOWER_REMOVE_VOLUMES=true
PROSOPO_ADMIN_ADDRESS=5EjTA28bKSbFPPyMbUjNtArxyqjwq38r1BapVmLZShaqEedV
PROSOPO_ADMIN_JSON=
PROSOPO_ADMIN_MNEMONIC=puppy cream effort carbon despair leg pyramid cotton endorse immense drill peasant
2 changes: 2 additions & 0 deletions dev/scripts/src/scripts/generateMnemonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ async function mnemonic(addToEnv: boolean) {
await updateEnvFile({
PROSOPO_PROVIDER_MNEMONIC: `"${mnemonic}"`,
PROSOPO_PROVIDER_ADDRESS: address,
PROSOPO_ADMIN_MNEMONIC: `"${mnemonic}"`,
PROSOPO_ADMIN_ADDRESS: address,
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion dev/scripts/src/setup/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ export async function setup(force: boolean) {
const config = defaultConfig();
const providerSecret = config.account.secret;
const pair = await getPairAsync(providerSecret);
const authAccount = await getPairAsync(config.authAccount.secret);

const env = new ProviderEnvironment(defaultConfig(), pair);
const env = new ProviderEnvironment(defaultConfig(), pair, authAccount);
await env.isReady();

defaultProvider.secret = mnemonic;
Expand Down
Loading

0 comments on commit a2aa975

Please sign in to comment.