fixture `Export`
.page(url)
const emailAddress = Selector('#email-address');
const emailPassword = Selector('#password');
const signInButton = Selector('.EmailSignIn_signInBtn__1u72_')
test(`Write credentials and successfully logs in to application`, async t => {
await t
.click(emailAddress)
.typeText( emailAddress, process.env.FAN_USERNAME)
.click(emailPassword)
.typeText(emailPassword, process.env.FAN_PASSWORD)
.click(signInButton)
.wait(100000)// don't mind this
.click(Selector('.Navbar_menuButton__3FuYX'))
});
I created a new test and everything works good but when the user successfully signs in to application it throws me 401 error unauthorized.
The error that I'm getting:
Related
I'm trying to add jest acceptance testing into an API repo (currently there are jest unit tests). The app is serverless aws. I'm working on getting a rough working p.o.c. API test against a staging url and I've put together this test file but it isn't working as expected and I don't have details to go on. I'd like to know how to return more details for a failure or what I'm missing to get it to hit the route as expected.
I'm returning 500 errors, but no real extra details. If I input an empty/invalid jwt token - still returns 500. If I remove the expect(response.status).toEqual(200); it "passes" but the console.log("blah blah blah here" + response); fails to show the response (or the "blah blah blah" for that matter). How can I return more details to see what I may be missing? Or adjust my request so it successfully hits that route and returns a better response?
My auth_impersonation p.o.c. test
import { agent as request } from 'supertest';
import express = require('express');
describe('Impersonate SE merchant', () => {
let app: express.Application = express();
let jwtToken = 'string I'm putting in manually for now';
it('returns a valid access token', async () => {
// within it block attempts here (below)
const response = await request(app)
.get('full staging url string here')
.auth(jwtToken, {type: 'bearer'});
console.log("blah blah blah here" + response);
// expect(response.status).toEqual(200);
})
});
Here's how the request looks in postman where the route works
Another go of the postman request, headers
I am trying to list objects and if this works later download/upload files to AWS S3. The code below throws an error. What am I doing incorrectly that this doesn't work? I've passed the accessKeyId and accessSecretKey in all possible ways below. I have a config and credentials file on mac and on windows I have just one awscredentials file and also set this on my windows
setx AWS_SDK_LOAD_CONFIG=1
CODE
const AWS = require('aws-sdk');
function listS3Objects(file, name, type) {
const s3bucket = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
accessSecretKey: process.env.AWS_SECRET_ACCESS_KEY,
// accessKeyId: 'my actual key in credentials file', //aws_access_key_id
// accessSecretKey: 'my actual secret key in credentials file', //aws_secret_access_key
region: "ap-southeast-1"
});
const params = {
Bucket: 'testbucketName',
};
s3bucket.listObjects(params, (err, data) => {
if (err) { throw err; }
/* eslint-disable no-console */
console.log('Success!');
console.log(data);
return data;
/* eslint-enable no-console */
});
}
const objs = listS3Objects()
//Test AWS Credentials
it('Tests', () => {
cy.log(objs)
})
ERROR
The following error originated from your test code, not from Cypress.
Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.
node_modules/aws-sdk/lib/config.js:400:1
398 |
399 | function credError(msg, err) {
400 | return new AWS.util.error(err || new Error(), {
| ^
401 | code: 'CredentialsError',
402 | message: msg,
403 | name: 'CredentialsError'
I'd troubleshoot it this way:
Can you run the script to upload or download separately? If not then its with the credentials.
if not credentials and this works perfectly can this script be imported into your spec and run? Let the script resolve and return a promise, then use the return value in your spec.
Refer this blog post.
Other options you could consider and cy.exec("aws command goes here")
I'm trying to add basic authentication to my app using the express-basic-auth. I'm following the instructions on this page, which also says "If a request is found to not be authorized, it will respond with HTTP 401" but my app simply replies with status code 200 when I do not pass any credentials
It seems I've incorrectly configured express-basic-auth. What have I done wrong?
const express = require('express')
const app = express()
const port = 3001
const basicAuth = require('express-basic-auth')
app.use(basicAuth({
users: { 'admin': 'supersecret' },
}))
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
Your code works. I confirmed with a nodejs client app that the basic auth works when given the right username and password and gives back a 401 when not given the right username and password or given no username and password.
The likely explanation is that you're not actually running your latest code and there's some previous server still running that doesn't require the basic auth.
You can verify that you are hitting the right server by adding
app.use((req, res, next) => {
console.log("got new server");
next();
});
before your basic auth middleware and verify that you see this log in the server console when you try your request. If you don't see this new log in the console, then you aren't hitting the newest code.
I have a Fixture which includes 2 Tests. Both tests accessing the same site with httpAuth().
The first request loads the page correctly and everything is ok. But the second test can't even load the page completely. A lot of requests are stuck on "Pending". On the IIS and also on our Proxy i see that every Request from Testcafe-Hammerhead is logged twice first with an 401 without credentials and then 200 with credentials. But when checking the log for the Second test for some request i only see the 401 Request without credentials.
After some minutes the test stops because of timeouts.
Here is a sample of the Test:
fixture("Getting Started").page(pageUrl).httpAuth(devAuth);
test("Test 1", async t => {
await t.maximizeWindow();
await t.debug();
var text = Selector("#content").find("h1");
var headerText = await text.innerText;
console.log("Found text: " +headerText);
await t.expect(headerText).eql("About our Team");
});
test("Test 2", async t => {
await t.maximizeWindow();
await t.debug();
var text = Selector("#content").find("h1");
var headerText = await text.innerText;
console.log("Found text: " +headerText);
await t.expect(headerText).eql("About our Team");
});
We found out that Testcafe opens for every request a new connection on our Proxy. This used all available connections and no new connections could be made which results that some requests are stuck in "Pending". That every request opens a new Connection on our Proxy is only via Testcafe. We will further investigate this.
Issue:
I am trying to get TestCafe to open an internal website that triggers a windows authentication pop up on opening, but the TestCafe built in Authentication feature doesn't work for some weird reason and the website complains with "401 - Unauthorized: Access is denied due to invalid credentials."
Note manually I can open the website with the same login credentials.
Also note the Authentication feature does work for other websites, and I am doing this at work, so there is a work proxy.
The site that TestCafe is failing to open up:
Is made up of a server name & port only & lives internally eg.
http://[ServerName]:[Port]
The Code:
Made up of 2 files....
The Test Script:
import {Selector} from 'testcafe';
fixture('My Test')
.page('http://[ServerIP]:[Port]/') // Also tried ('http://[ServerName]:[Port]')
.httpAuth({
username: 'domain\name',
password: 'password_here'
})
test ('Opening this internal site', async t => {
await t
.debug()
});
The Runner file:
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', '8081')
.then(tc => {
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src([
'My_Test.js'
])
.browsers('chrome')
.useProxy('webproxy01:8080', '[ServerIP]:[Port]') // I tried including the website that I want to test incase it needs to be ByPassed
.run({
skipJsErrors: true,
concurrency: 1
})
})
.then(failedCount => {
console.log(`Tests failed: ` + failedCount);
testcafe.close();
});
Just to add I've tried this too and it doesn't work either:
.httpAuth({
username: 'name',
password: 'password_here',
domain: 'domain_here',
workstation: 'computer_name'
})
Many thanks!