How do I connect to a fake SMTP server using Loopback - node.js

This similar to to this question, but intstead I am trying to connect to this fake smtp-server
https://www.npmjs.com/package/smtp-sink
I run this server using npm i smtp-sink and smtp-sink and it seems fine
Here is how I have configured my datasource:
"emailDataSource": {
"connector": "mail",
"transports": [{
"type": "smtp",
"host": "localhost",
"secure": false,
"port": 1025,
"tls": {
"rejectUnauthorized": false
}
}]
}
and sending the email through an endpoint as such: (this 9is inside a remote method)
var options = {
to: "bla#bla.com",
subject: "subject",
text: "text",
html: "html"
};
app.models.Email.send(options, function (err, mail) {
cb(null || err, null || mail);
});
However, I now get the following error
{
"error": {
"name": "Error",
"status": 500,
"message": "Data command failed",
"code": "EENVELOPE",
"response": "503 Bad sequence: MAIL expected",
"responseCode": 503,
"stack": "Error: Data command failed\n at SMTPConnection._formatError (/Users/admin/Documents/Projects/otogo/otogo-api-server/build/node_modules/loopback/node_modules/nodemailer/node_modules/nodemailer-smtp-transport/node_modules/smtp-connection/src/smtp-connection.js:388:15)\n at SMTPConnection._actionDATA (/Users/admin/Documents/Projects/otogo/otogo-api-server/build/node_modules/loopback/node_modules/nodemailer/node_modules/nodemailer-smtp-transport/node_modules/smtp-connection/src/smtp-connection.js:909:30)\n at SMTPConnection.<anonymous> (/Users/admin/Documents/Projects/otogo/otogo-api-server/build/node_modules/loopback/node_modules/nodemailer/node_modules/nodemailer-smtp-transport/node_modules/smtp-connection/src/smtp-connection.js:885:22)\n at SMTPConnection._processResponse (/Users/admin/Documents/Projects/otogo/otogo-api-server/build/node_modules/loopback/node_modules/nodemailer/node_modules/nodemailer-smtp-transport/node_modules/smtp-connection/src/smtp-connection.js:507:16)\n at SMTPConnection._onData (/Users/admin/Documents/Projects/otogo/otogo-api-server/build/node_modules/loopback/node_modules/nodemailer/node_modules/nodemailer-smtp-transport/node_modules/smtp-connection/src/smtp-connection.js:357:10)\n at Socket.emit (events.js:95:17)\n at Socket.<anonymous> (_stream_readable.js:764:14)\n at Socket.emit (events.js:92:17)\n at emitReadable_ (_stream_readable.js:426:10)\n at emitReadable (_stream_readable.js:422:5)"
}
}

Look at my example here on how to send emails: https://github.com/strongloop/loopback-faq-email
As for the NPM package, I've never used it so I can't help you there.

Related

Strapi api not giving a response when registering user even though it was updated in the admin panel

I am using Strapi with postgres to register a new Strapi end user and I am using the following code to send a post request with the new user's credentials:
//...
try {
// encrypt the user password
const encryptedUserPassword = await bcrypt.hash(password, 10);
const response = await axios.post(
"http://localhost:1337/api/auth/local/register",
{
username,
email: email.toLowerCase(),
password: encryptedUserPassword,
}
);
} catch (err) {
console.log(err);
res.status(500).send({ message: ["Registration failed"], error: err });
}
// ...
The problem that I am facing is that whenever I send the post request, the data is being successfully updated in the Strapi admin panel and eventually in the postgres database but it is not returning a successful response and it continues to process until it throws an Axios error even though the data is updated in my Strapi admin panel.
This is the error that I received when I send the post request to register a new user:
{
"message": [
"Registration failed"
],
"error": {
"message": "Request failed with status code 400",
"name": "AxiosError",
"config": {
"transitional": {
"silentJSONParsing": true,
"forcedJSONParsing": true,
"clarifyTimeoutError": false
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1,
"env": {},
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"User-Agent": "axios/0.27.2",
"Content-Length": 130
},
"method": "post",
"url": "http://localhost:1337/api/auth/local/register",
"data": "{\"username\":\"testuser04\",\"email\":\"testuser09#email.com\",\"password\":\"$2a$10$pqeADn.WL4BqHYpTonVl2.KYqoxtuJZyvdpgc659W90zmsu4Wo2jW\"}"
},
"code": "ERR_BAD_REQUEST",
"status": 400
}
}
I am using the recommended Strapi node version 14.19.3 with the following package.json dependencies:
"devDependencies": {},
"dependencies": {
"#strapi/strapi": "4.2.3",
"#strapi/plugin-users-permissions": "4.2.3",
"#strapi/plugin-i18n": "4.2.3",
"pg": "8.6.0"
},
Could someone please help me or give me some tips on what I am doing wrong? Thank you in advance
Well, I just resolved this problem. It turns out that just needed to set the default value for the email confirmation in the admin panel to false. Also, I needed to authorize my application to make requests directly to the API

Nightwatch : Unable to create new service : ChromeDriverService

I am trying to automate a simple test case using Nightwatch framework of validating a login. I have followed the steps mentioned on : https://www.softwaretestingmaterial.com/browser-automation-with-nightwatch-and-selenium/
The problem arises when I execute the command node nightwatch tests/bing_test.js in node.js command prompt which results in a error message.
Below is my nightwatch.json configs :
{
"src_folders": ["tests"],
"output_folder": "reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "",
"globals_path": "",
"selenium": {
"start_process": true,
"server_path": "./lib/selenium-server-standalone-3.8.1.jar",
"log_path": "./reports",
"host": "127.0.0.1",
"port": 4445,
"cli_args": {
"webdriver.chrome.driver": "./lib/drivers/chromedriver.exe",
"webdriver.gecko.driver": "./lib/drivers/geckodriver.exe",
"webdriver.edge.driver": "./lib/drivers/MicrosoftWebDriver.exe"
}
},
"test_settings": {
"default": {
"launch_url": "http://localhost",
"selenium_port": 4445,
"selenium_host": "localhost",
"silent": true,
"screenshots": {
"enabled": true,
"path": "./reports/screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"marionette": true,
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome"
}
},
"firefox": {
"desiredCapabilities": {
"browserName": "firefox"
}
},
"edge": {
"desiredCapabilities": {
"browserName": "MicrosoftEdge"
}
}
}
}
Error Message :
[Bing Test] Test Suite
======================
Response 500 POST /wd/hub/session (363ms)
{ value:
{ error:
[ "Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'",
"System info: host: 'PDC2LAP-7173253', ip: '192.168.43.196', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'",
'Driver info: driver.version: unknown' ],
message: 'Unable to create new service: ChromeDriverService' },
status: 33 }
An error occurred while retrieving a new session: "Unable to create new service: ChromeDriverService"
at endReadableNT (_stream_readable.js:1129:12)
at processTicksAndRejections (internal/process/next_tick.js:76:17)
_________________________________________________
TEST FAILURE: 1 error during execution 0 tests failed, 0 passed. 2.886s
× bing_test
An error occurred while retrieving a new session: "Unable to create new service: ChromeDriverService"
at endReadableNT (_stream_readable.js:1129:12)
at processTicksAndRejections (internal/process/next_tick.js:76:17)
SKIPPED:
- Bing search test
I have tried to debug the issue by going through the comments on GIT forum by setting "webdriver.chrome.driver": "" and "start_process": false, but none of the two worked.
ChromeDriver Version - v72
Selenium Standalone Jar - 3.8.1
Please feel free to guide me to any existing answer/documentation that persists for this issue.

Laravel Echo Server can not be authenticated, got HTTP status 500

I've installed both Laravel echo server and Laravel echo client.
Following is the laravel-echo-server.json configuration.
{
"authHost": "http://taxation.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "APP_ID",
"key": "someKey"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": "127.0.0.1",
"port": "3000",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": ""
}
The following script listens for channel events. It builds fine with npm run dev.
import Echo from 'laravel-echo'
let token = document.head.querySelector('meta[name="token"]');
if (token) {
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
window.Echo = new Echo({
broadcaster: 'socket.io',
host: '127.0.0.1:3000',
reconnectionAttempts: 5
});
window.Echo.join('checked-in-1')
.listen('.user.checked_in', (e) => {
console.log(e);
});
When trying to listen for any event on start laravel-echo-server command. It keeps throwing Client can not be authenticated, got HTTP status 500.
Note :
I really didn't find anything helpful on laravel-echo-serve nor on google.
Any help will be appreciated a lot.
Laravel V5.4
Thanks
Just getting the issue because of CSRF token. Didn't passed the token to the echo.
window.Echo = new Echo({
broadcaster: 'socket.io',
host: '127.0.0.1:3000',
reconnectionAttempts: 5,
csrfToken: token.content <--
});

Inserting events in to google calendar using gives an error 404 "NOT FOUND"

I am creating a Node JS (Express) web app that will display a user's Google Calendar events, once they have logged in and insert events events into google calendar from my database.
I am trying to insert events via the Google Calendar API with a service account
Code I used :
var googleapis = require("googleapis"),
googleCal = googleapis.calendar("v3"),
serviceEmail = "*****#*******gserviceaccount.com",
serviceKeyFile = "./key.p12";
var authClient = new googleapis.auth.JWT(
serviceEmail,
serviceKeyFile,
null,
["https://www.googleapis.com/auth/calendar"]
);
authClient.authorize(function (err, tokens) {
console.log("tokens"+JSON.stringify(tokens));
if (err) {
console.log(err);
} else {
googleCal.events.list({
auth: authClient,
calendarId: "*********#gmail.com",
fields: {
items: ["end","start","summary"]
}
}, function (err, CL) {
if (err) {
console.log(err);
} else {
console.log("calendar"+CL);
}
});
}
})
var event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2017-07-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2017-07-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees': [
{'email': 'lpage#example.com'},
{'email': 'sbrin#example.com'},
],
'reminders': {
'useDefault': false,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
};
googleCal.events.insert({
auth: authClient,
calendarId:'primary',
resource: event,
}, function (err, events) {
if (err) {
console.log("there is an error"+err);
} else {
console.log(events);
console.log("events are created successfully");
}
})
My problem is while executing it is displaying an error like
{ Error: Not Found
at Request._callback (D:\studentportal\node_modules\google-auth-library\lib\transporters.js:85:15)
at Request.self.callback (D:\studentportal\node_modules\request\request.js:186:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request. (D:\studentportal\node_modules\request\request.js:1081:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage. (D:\studentportal\node_modules\request\request.js:1001:12)
at IncomingMessage.g (events.js:291:16)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9) code: 404, errors: [ { domain: 'global', reason: 'notFound',
message: 'Not Found' } ] }
What is the solution for this?
Try to check this and hopefully it helps you Handle API Error: 404
404: Not Found
The specified resource was not found. This can happen in several
cases. Here are some examples:
when the requested resource (with the provided ID) has never existed
when accessing a calendar that the user can not access
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}

tedious.js set requestTimeout = 0 but still got timed out

I have this config file:
{
"userName": "user",
"password": "pass",
"server": "shrd-cw",
"options": {
"encrypt": true,
"requestTimeout": 0
}
}
However, I still received requestTimeout error:
{ [RequestError: Timeout: Request failed to complete in 15000ms]
name: 'RequestError',
message: 'Timeout: Request failed to complete in 15000ms',
code: 'ETIMEOUT' }

Resources