Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/dapp-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ jobs:

test:
runs-on: ubuntu-latest
environment: bellecour-dev
strategy:
matrix:
environment: ['bellecour-dev', 'arbitrum-sepolia-dev']
environment: ${{ matrix.environment }}
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY }}
Expand All @@ -48,6 +51,7 @@ jobs:
MJ_SENDER: ${{ secrets.MAILJET_SENDER }}
MAILGUN_APIKEY: ${{ secrets.MAILGUN_APIKEY }}
WEB3MAIL_WHITELISTED_APPS: ${{ vars.WEB3MAIL_WHITELISTED_APPS }}
POCO_SUBGRAPH_URL: ${{ vars.POCO_SUBGRAPH_URL }}
steps:
- uses: actions/checkout@v4

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dapp-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ jobs:
MJ_SENDER: ${{ secrets.MAILJET_SENDER }}
MAILGUN_APIKEY: ${{ secrets.MAILGUN_APIKEY }}
WEB3MAIL_WHITELISTED_APPS: ${{ vars.WEB3MAIL_WHITELISTED_APPS }}
POCO_SUBGRAPH_URL: ${{ vars.POCO_SUBGRAPH_URL }}
RPC_URL: ${{ secrets.RPC_URL }}
run: |
cd deployment-dapp
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/sdk-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: web3mail-sdk-ci

on: [pull_request]
on:
pull_request:
paths-ignore:
- '.github/**'
- 'dapp/**'
- 'demo/**'
- 'deployment-dapp/**'
- 'technical-design/**'

concurrency:
group: ${{ github.ref }}-pr-test
Expand Down
9 changes: 5 additions & 4 deletions dapp/src/checkEmailPreviousValidation.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const { request, gql } = require('graphql-request');

async function checkEmailPreviousValidation({ datasetAddress, dappAddresses }) {
const pocoSubgraphUrl =
'https://thegraph.bellecour.iex.ec/subgraphs/name/bellecour/poco-v5';

async function checkEmailPreviousValidation({
datasetAddress,
dappAddresses,
pocoSubgraphUrl,
}) {
const query = gql`
query checkSuccessfulTaskQuery($apps: [String!], $dataset: String!) {
tasks(
Expand Down Expand Up @@ -38,7 +39,7 @@
);
});
} catch (error) {
console.error(

Check warning on line 42 in dapp/src/checkEmailPreviousValidation.js

View workflow job for this annotation

GitHub Actions / check-code

Unexpected console statement
'GraphQL error:',
error.response?.errors || error.message || error
);
Expand Down
1 change: 1 addition & 0 deletions dapp/src/sendEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
async function writeTaskOutput(path, message) {
try {
await fs.writeFile(path, message);
console.log(`File successfully written at path: ${path}`);

Check warning on line 24 in dapp/src/sendEmail.js

View workflow job for this annotation

GitHub Actions / check-code

Unexpected console statement
} catch {
console.error(`Failed to write Task Output`);

Check warning on line 26 in dapp/src/sendEmail.js

View workflow job for this annotation

GitHub Actions / check-code

Unexpected console statement
process.exit(1);
}
}
Expand Down Expand Up @@ -76,11 +76,12 @@
let isEmailValidated = await checkEmailPreviousValidation({
datasetAddress: protectedData.email,
dappAddresses: appDeveloperSecret.WEB3MAIL_WHITELISTED_APPS,
pocoSubgraphUrl: appDeveloperSecret.POCO_SUBGRAPH_URL,
});

// Step 2: If not, try Mailgun
if (!isEmailValidated) {
console.log('No prior verification found. Trying Mailgun...');

Check warning on line 84 in dapp/src/sendEmail.js

View workflow job for this annotation

GitHub Actions / check-code

Unexpected console statement
const mailgunResult = await validateEmailAddress({
emailAddress: protectedData.email,
mailgunApiKey: appDeveloperSecret.MAILGUN_APIKEY,
Expand All @@ -91,12 +92,12 @@
} else if (mailgunResult === false) {
throw Error('The protected email address seems to be invalid.');
} else {
console.warn(

Check warning on line 95 in dapp/src/sendEmail.js

View workflow job for this annotation

GitHub Actions / check-code

Unexpected console statement
'Mailgun verification failed or was unreachable. Proceeding without check.'
);
}
} else {
console.log('Email already verified, skipping Mailgun check.');

Check warning on line 100 in dapp/src/sendEmail.js

View workflow job for this annotation

GitHub Actions / check-code

Unexpected console statement
}

// Step 3: Decrypt email content
Expand Down
1 change: 1 addition & 0 deletions dapp/src/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const appSecretSchema = Joi.object({
MJ_SENDER: Joi.string().email().required(),
MAILGUN_APIKEY: Joi.string().required(),
WEB3MAIL_WHITELISTED_APPS: Joi.array().items(Joi.string()).required(),
POCO_SUBGRAPH_URL: Joi.string().uri().required(),
});

function validateAppSecret(obj) {
Expand Down
29 changes: 28 additions & 1 deletion dapp/tests/e2e/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('sendEmail', () => {
MAILGUN_APIKEY: 'xxx',
WEB3MAIL_WHITELISTED_APPS:
'["0xa638bf4665ce7bd7021a4a12416ea7a0a3272b6f"]',
POCO_SUBGRAPH_URL: 'https://fake-poco.subgraph.iex.ec',
});
// requester secret setup
process.env.IEXEC_REQUESTER_SECRET_1 = JSON.stringify({
Expand Down Expand Up @@ -54,6 +55,7 @@ describe('sendEmail', () => {
MAILGUN_APIKEY: 'xxx',
WEB3MAIL_WHITELISTED_APPS:
'["0xa638bf4665ce7bd7021a4a12416ea7a0a3272b6f"]',
POCO_SUBGRAPH_URL: 'https://fake-poco.subgraph.iex.ec',
});
await expect(() => start()).rejects.toThrow(
Error('App secret error: "MJ_APIKEY_PUBLIC" is required')
Expand All @@ -69,6 +71,7 @@ describe('sendEmail', () => {
MAILGUN_APIKEY: 'xxx',
WEB3MAIL_WHITELISTED_APPS:
'["0xa638bf4665ce7bd7021a4a12416ea7a0a3272b6f"]',
POCO_SUBGRAPH_URL: 'https://fake-poco.subgraph.iex.ec',
});
await expect(() => start()).rejects.toThrow(
Error('App secret error: "MJ_APIKEY_PRIVATE" is required')
Expand All @@ -84,6 +87,7 @@ describe('sendEmail', () => {
MAILGUN_APIKEY: 'xxx',
WEB3MAIL_WHITELISTED_APPS:
'["0xa638bf4665ce7bd7021a4a12416ea7a0a3272b6f"]',
POCO_SUBGRAPH_URL: 'https://fake-poco.subgraph.iex.ec',
});
await expect(() => start()).rejects.toThrow(
Error('App secret error: "MJ_SENDER" is required')
Expand All @@ -99,6 +103,7 @@ describe('sendEmail', () => {
MJ_SENDER: '[email protected]',
WEB3MAIL_WHITELISTED_APPS:
'["0xa638bf4665ce7bd7021a4a12416ea7a0a3272b6f"]',
POCO_SUBGRAPH_URL: 'https://fake-poco.subgraph.iex.ec',
});
await expect(() => start()).rejects.toThrow(
Error('App secret error: "MAILGUN_APIKEY" is required')
Expand All @@ -113,6 +118,7 @@ describe('sendEmail', () => {
MJ_APIKEY_PRIVATE: 'xxx',
MAILGUN_APIKEY: 'xxx',
MJ_SENDER: '[email protected]',
POCO_SUBGRAPH_URL: 'https://fake-poco.subgraph.iex.ec',
});
await expect(() => start()).rejects.toThrow(
Error('App secret error: "WEB3MAIL_WHITELISTED_APPS" is required')
Expand All @@ -121,6 +127,22 @@ describe('sendEmail', () => {
const out = await fsPromises.readdir(process.env.IEXEC_OUT);
expect(out).toStrictEqual([]);
});
it('should fail if POCO_SUBGRAPH_URL in developer secret is missing', async () => {
process.env.IEXEC_APP_DEVELOPER_SECRET = JSON.stringify({
MJ_APIKEY_PUBLIC: 'xxx',
MJ_APIKEY_PRIVATE: 'xxx',
MAILGUN_APIKEY: 'xxx',
MJ_SENDER: '[email protected]',
WEB3MAIL_WHITELISTED_APPS:
'["0xa638bf4665ce7bd7021a4a12416ea7a0a3272b6f"]',
});
await expect(() => start()).rejects.toThrow(
Error('App secret error: "POCO_SUBGRAPH_URL" is required')
);
// output should be empty
const out = await fsPromises.readdir(process.env.IEXEC_OUT);
expect(out).toStrictEqual([]);
});
});

describe('with bad IEXEC_REQUESTER_SECRET_1', () => {
Expand Down Expand Up @@ -286,6 +308,7 @@ describe('sendEmail', () => {
MAILGUN_APIKEY: 'fake',
WEB3MAIL_WHITELISTED_APPS:
'["0xa638bf4665ce7bd7021a4a12416ea7a0a3272b6f"]',
POCO_SUBGRAPH_URL: 'https://fake-poco.subgraph.iex.ec',
});
// check the error is not an email validation error (mailgun validation is skipped, mailjet rejects)
await expect(() => start()).rejects.toThrow(
Expand All @@ -303,6 +326,7 @@ describe('sendEmail', () => {
MAILGUN_APIKEY: 'xxx',
WEB3MAIL_WHITELISTED_APPS:
'["0xa638bf4665ce7bd7021a4a12416ea7a0a3272b6f"]',
POCO_SUBGRAPH_URL: 'https://fake-poco.subgraph.iex.ec',
});
await expect(() => start()).rejects.toThrow(
Error('Failed to send email')
Expand All @@ -321,7 +345,8 @@ describe('sendEmail', () => {
(process.env.MJ_APIKEY_PUBLIC &&
process.env.MJ_APIKEY_PRIVATE &&
process.env.MJ_SENDER &&
process.env.MAILGUN_APIKEY)
process.env.MAILGUN_APIKEY &&
process.env.POCO_SUBGRAPH_URL)
) {
describe('with credentials', () => {
beforeEach(() => {
Expand All @@ -332,13 +357,15 @@ describe('sendEmail', () => {
MJ_SENDER,
MAILGUN_APIKEY,
WEB3MAIL_WHITELISTED_APPS,
POCO_SUBGRAPH_URL,
} = process.env;
process.env.IEXEC_APP_DEVELOPER_SECRET = JSON.stringify({
MJ_APIKEY_PUBLIC,
MJ_APIKEY_PRIVATE,
MJ_SENDER,
MAILGUN_APIKEY,
WEB3MAIL_WHITELISTED_APPS,
POCO_SUBGRAPH_URL,
});

// requester secret setup
Expand Down
4 changes: 3 additions & 1 deletion dapp/tests/unit/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('validateAppSecret function', () => {
WEB3MAIL_WHITELISTED_APPS: JSON.parse(
'["0xa638bf4665ce7bd7021a4a12416ea7a0a3272b6f"]'
),
POCO_SUBGRAPH_URL: 'https://fake-poco.subgraph.iex.ec',
})
).not.toThrow();
});
Expand Down Expand Up @@ -94,10 +95,11 @@ describe('validateAppSecret function', () => {
MJ_SENDER: 'foo',
MAILGUN_APIKEY: '',
WEB3MAIL_WHITELISTED_APPS: '[4]',
POCO_SUBGRAPH_URL: 'not-a-url',
})
).toThrow(
Error(
'App secret error: "MJ_APIKEY_PUBLIC" must be a string; "MJ_APIKEY_PRIVATE" is not allowed to be empty; "MJ_SENDER" must be a valid email; "MAILGUN_APIKEY" is not allowed to be empty; "WEB3MAIL_WHITELISTED_APPS" must be an array'
'App secret error: "MJ_APIKEY_PUBLIC" must be a string; "MJ_APIKEY_PRIVATE" is not allowed to be empty; "MJ_SENDER" must be a valid email; "MAILGUN_APIKEY" is not allowed to be empty; "WEB3MAIL_WHITELISTED_APPS" must be an array; "POCO_SUBGRAPH_URL" must be a valid uri'
)
);
});
Expand Down
3 changes: 3 additions & 0 deletions deployment-dapp/src/pushSecretScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const main = async () => {
MJ_SENDER,
MAILGUN_APIKEY,
WEB3MAIL_WHITELISTED_APPS,
POCO_SUBGRAPH_URL,
} = process.env;

if (!WALLET_PRIVATE_KEY)
Expand All @@ -20,6 +21,7 @@ const main = async () => {
if (!MAILGUN_APIKEY) throw Error('Missing env MAILGUN_APIKEY');
if (WEB3MAIL_WHITELISTED_APPS === undefined)
throw Error('Missing env WEB3MAIL_WHITELISTED_APPS');
if (!POCO_SUBGRAPH_URL) throw Error('Missing env POCO_SUBGRAPH_URL');

if (!WALLET_PRIVATE_KEY)
throw Error(`Missing WALLET_PRIVATE_KEY environment variable`);
Expand All @@ -40,6 +42,7 @@ const main = async () => {
MJ_SENDER,
MAILGUN_APIKEY,
WEB3MAIL_WHITELISTED_APPS: JSON.stringify(fullWhitelistedApps),
POCO_SUBGRAPH_URL,
});

await pushSecret(iexec, appAddress, jsonSecret);
Expand Down
Loading