Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got this crash when testing | sending mails with aws SES is not working! #10864

Open
BennyAlex opened this issue May 6, 2024 · 3 comments
Open
Labels
bug Something isn't working crash An issue that could cause a crash

Comments

@BennyAlex
Copy link

BennyAlex commented May 6, 2024

How can we reproduce the crash?

No response

JavaScript/TypeScript code that reproduces the crash?

import { routes, startServer } from '@/startServer';
import mailUtils from '@/utils/mailUtils';
import * as Sentry from '@sentry/node';
import { afterAll, beforeAll, describe, test } from 'bun:test';
import fetchWrapper from './fetchWrapper';

// start the server before running the tests
console.log('\n\nStarting server...\n');

beforeAll(async () => {
    startServer();
});

const errors: any[] = [];

const prodReceiver = [
    'bla@eye-able.com',
    'bla2@eye-able.com',
    'bla3@eye-able.com'
];

const additionalParams: Record<string, any> = {
    /* '/search/auditlicenses': {
        searchterm: 'eye-able.com'
    },
    '/search/assistlicensesbydomain': {
        domain: 'eye-able.com'
    },
    '/search/reportentries': {
        searchterm: 'eye-able.com'
    },
    '/search/users': {
        searchterm: 'api tester'
    }, */
    '/search/assistlicenses': {
        searchterm: 'eye-able.com'
    },
    '/search/organisations': {
        searchterm: 'web inclusion'
    },
    '/assistconfig': {
        domain: 'eye-able.com'
    },
    '/translatelicense': {
        domain: 'eye-able.com',
        key: 'bla'
    },
    '/licenseconstraints': {
        userid: 3
    },
    '/users': {
        id: 3
    },
    '/assistlicenses': {
        domain: 'eye-able.com'
    },
    '/reportentries/config': {
        entryid: 1
    }
};

if (Object.keys(routes).length < 20) {
    await onError('No or not enough routes found. Routes: ' + JSON.stringify(routes, null, 4));
    throw new Error('No or not enough routes found. Routes: ' + JSON.stringify(routes, null, 4));
}

let cookie = '';

async function onError(error: any) {
    if (Bun.env.PROD) {
        Sentry.captureException('CRITICAL API ERROR!: ' + error);
    }

    console.log('\nSending error mail...\n');

    return await mailUtils.sendCriticalErrorMail({
        receiver: Bun.env.PROD
            ? prodReceiver
            : ['bla@eye-able.com', 'blabla@gmail.com'],
        data: {
            errorInfo: error
        }
    });
}

describe('API tests', () => {
    /*  afterAll(async () => {
        
        // After all tests are done, check if any test failed
        if (errors.length) {
            console.error('afterAll | At least one test failed!');
            console.log('Errors:', JSON.stringify(errors, null, 4));
            await onError(errors);
        }

        const { numFailedTests } = jest.getState().testResults;
        if (numFailedTests > 0) {
            console.error('Some tests failed!');
        } else {
            console.log('All tests passed!');
        }
    }); */
    // Check if any test failed after running all tests
    afterAll(async () => {
        if (errors.length) {
            console.error('At least one test failed!');
            console.log('Errors:', JSON.stringify(errors, null, 4));
            await onError(errors);
        } else {
            console.log('All tests passed!');
        }
    });

    // Login and retrieve token
    beforeAll(async () => {
        try {
            if (!Bun.env.TEST_PASSWORD) {
                throw new Error('TEST_PASSWORD not set in .env file');
            }

            const res = await fetchWrapper('/authentication/login', {
                method: 'POST',
                body: JSON.stringify({
                    email: blabla@eye-able.com',
                    password: Bun.env.TEST_PASSWORD
                }),
                headers: {
                    'Content-Type': 'application/json'
                }
            });

            cookie = res.headers.get('SET-COOKIE') || '';
            if (!cookie) {
                throw new Error('Cookie not found in login response');
            }
        } catch (error) {
            console.error('Login failed:', error);
            await onError('API Login failed!');
            throw new Error('Login failed, stopping all tests.'); // This will stop further tests from running in this describe block
        }
    });

    // Test all GET routes
    describe('checking GET methods of all routes', () => {
        for (let [path, handlers] of Object.entries(routes)) {
            for (const handler of handlers) {
                if (handler.method && handler.method === 'GET') {
                    test(`GET ${path}`, async () => {
                        try {
                            if (additionalParams[path]) {
                                const params = new URLSearchParams();
                                for (const [key, value] of Object.entries(additionalParams[path])) {
                                    params.set(key, String(value));
                                }
                                path += '?' + params.toString();
                            }

                            await fetchWrapper(path, {}, cookie);
                        } catch (error) {
                            console.error(`GET ${path} failed:`, error);
                            errors.push(error);
                            throw error;
                        }
                    });
                }
            }
        }
    });
});

Relevant log output

No response

Stack Trace (bun.report)

Bun v1.1.6 (e58d67b) on linux x86_64 [TestCommand]

Segmentation fault at address 0x00000000

@BennyAlex BennyAlex added bug Something isn't working crash An issue that could cause a crash labels May 6, 2024
@BennyAlex
Copy link
Author

I thinks its related to mail sending which is done via amazon SES

@BennyAlex
Copy link
Author

BennyAlex commented May 6, 2024

import { SESClient, SendTemplatedEmailCommand } from '@aws-sdk/client-ses';

const id = Bun.env.AWS_ACCESS_KEY_ID || '';
const secret = Bun.env.AWS_SECRET_ACCESS_KEY || '';

if (!id || !secret) {
    throw new Error('No AWS credentials found');
}

export const mailClient = new SESClient({
    region: 'eu-central-1',
    credentials: {
        accessKeyId: id,
        secretAccessKey: secret
    }
});

@BennyAlex BennyAlex changed the title Got this error when testing Got this crash when testing May 6, 2024
@BennyAlex
Copy link
Author

BennyAlex commented May 6, 2024

I can't send any emails with SES!
Both with the old v2 version and also the v3 version

@BennyAlex BennyAlex changed the title Got this crash when testing Got this crash when testing | sending mails with aws SES is not working! May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash An issue that could cause a crash
Projects
None yet
Development

No branches or pull requests

1 participant