Delete Facebook account using Cypress - testing

I'd like to delete my Facebook account, but actually, I'd like to obfuscate my data first.
Cypress seems to be a great fit. However, I'm not getting past the login: "Your request couldn't be processed"
Here is my code:
describe('obfuscate data', () => {
before(() => {
cy.visit('https://facebook.com');
cy.get('#email').type(email);
cy.get('#pass').type(password);
cy.get('form button').click();
});
it('should be logged in', () => {
cy.contains('What\'s on your mind, XXXX?');
});
});
What is different in Cypress, from an actual browser? When I open a new browser tab in Cypress and go to Facebook.com, I can manually log in fine.
Facebook login error

Using cypress on 3rd party sites (ones you do not control) is highly discouraged: https://docs.cypress.io/guides/references/best-practices#Visiting-external-sites
Also, I'm pretty sure deleting accounts using automated scripts also breaks couple of facebooks terms and conditions in case you care.

Related

node express multer fast-csv pug file upload

I trying to upload a file using pug, multer and express.
The pug form looks like this
form(method='POST' enctype="multipart/form-data")
div.form-group
input#uploaddata.form-control(type='file', name='uploaddata' )
br
button.btn.btn-primary(type='submit' name='uploaddata') Upload
The server code looks like this (taken out of context)
.post('/uploaddata', function(req, res, next) {
upload.single('uploaddata',function(err) {
if(err){
throw err;
} else {
res.json({success : "File upload sucessfully.", status : 200});
}
});
})
My issue is that while the file uploads successfully, the success message is not shown on the same page, ie: a new page is loaded showing
{success : "File upload sucessfully.", status : 200}
As an example for other elements (link clicks) the message is displayed via such javascript:
$("#importdata").on('click', function(){
$.get( "/import", function( data ) {
$("#message").show().html(data['success']);
});
});
I tried doing a pure javascript in order to workaround the default form behaviour but no luck.
Your issue has to do with mixing form submissions and AJAX concepts. To be specific, you are submitting a form then returning a value appropriate to an AJAX API. You need to choose one or the other for this to work properly.
If you choose to submit this as a form you can't use res.json, you need to switch to res.render or res.redirect instead to render the page again. You are seeing exactly what you are telling node/express to do with res.json - JSON output. Rendering or redirecting is what you want to do here.
Here is the MDN primer on forms and also a tutorial specific to express.js.
Alternatively, if you choose to handle this with an AJAX API, you need to use jquery, fetch, axios, or similar in the browser to send the request and handle the response. This won't cause the page to reload, but you do need to handle the response somehow and modify the page, otherwise the user will just sit there wondering what has happened.
MDN has a great primer on AJAX that will help you get started there. If you are going down this path also make sure you read up on restful API design.
Neither one is inherently a better strategy, both methods are used in large-scale production applications. However, you do need to choose one or the other and not mix them as you have above.

Google plus login requires permission on every login

I have implemented a Facebook, Twitter and Google plus login to my website. For Facebook and Twitter the user needs to give permission to the app one time, unless i make a change in the required information.
Google Plus however asks for permission for my app every single time. And I can not find anywhere to configure the app in only requesting this once.
You need to set the 'approvalprompt' to 'auto'
function render() {
gapi.signin.render('customBtn', {
//'callback': 'signinCallback',
'clientid': '841077041629.apps.googleusercontent.com',
'cookiepolicy': 'single_host_origin',
'requestvisibleactions': 'http://schemas.google.com/AddActivity',
'scope': 'https://www.googleapis.com/auth/plus.login'
'approvalprompt': 'auto'
});
}
Remove the approvalprompt parameter from your sign-in code. I assume you copied from one of the examples that uses this parameter to ensure that the example is always in a new state.

FB.logout() only from the application using javaScript SDK

I get a user's data using the Facebook JavaScript SDK like this:
FB.login(function(response){
// some code here
userid = response.authResponse.userId;
});
If the user id is odd (undesired one), then I call:
FB.logout();
This will make the user logout from my application and their Facebook account as well.
I want it to only log out the user out from my application. They should not be logged out from their Facebook account.
Below is the code I use to initialize the FB variable:
FB.init({appId: 'XXXXXXXXXXXXX', cookie: true, status: true, xfbml : true});
If a user logs in to my application then I get the response. The response has the status, access_token and user_id.
Which variable should I use to achieve only logging them out of my application and not Facebook?
I am also having the same problem, looks like we need to use both PHP and Javascript SDK to get and maintain the state for App only logout. You can check out the tutorial here, I am just looking into this, so I have not actually checked if it works.

How to use the Facebook JavaScript SDK with the sorcery gem

I followed the guide provided here by Sorcery about handling user logins with Facebook.
# callback method called by Facebook after getting the authorization by the user
if user = login_from(provider) # provider == "facebook"
redirect_to root_path #, :notice => "Logged in from #{provider.titleize}!"
else
begin
user = create_from(provider)
...
However it only requires that my users leave my site to go to the Facebook page and then get redirected here.
What I would like to achieve is what I see when using the Facebook JavaScript SDK which is a clean popup right in my page. To achieve this I followed a tutorial on Railscasts:
$('#sign_in').click (e) ->
e.preventDefault()
FB.login (response) ->
window.location = '/auth/facebook/callback' if response.authResponse
However, the authResponse only contains an accessToken and a signedRequest and a userid while Sorcery requires a code.
Is there anyway to do this properly (or get the code using the accessToken?).
However, the authResponse only contains an accessToken and a signedRequest and a userid while Sorcery requires a code.
Is there anyway to do this properly (or get the code using the accessToken?).
In the server-side flow, the code is just an intermediate step in getting the access token – app gets code, and exchanges code for an access token.
Since in the client-side flow you already get an access token when it’s finished – it does not get any more “proper” than that.
So you have two options:
either refactor your Sorcery-thingie, so that it skips the step where it gets a code and exchanges that for an access token, and directly “set” the access token yourself after getting it (wherever Sorcery might want it to be set); or
stick to the server-side flow, but open that yourself in a popup window. Then you’ll still get the code, but you’ll get it inside the popup window. So you’d have to close the popup window and maybe reload your original window yourself afterwards.

Testing a live website with QUnit

Can I test live websites using QUnit? For example, can I write a test that says:
Go to google.com
Enter a search term
Click 'Google Search'
Check there are 10 results and 2 ads
Would QUnit be an appropriate tool for this kind of "live" testing?
You can achieve that using qunit if qunit is the only tool/testing framework that is available for you and the page you will be testing allows GET requests.
How to do that qunit is you can make an ajax call to the page you are testing using JSONP and get the response. Then you would assert certain elements on the response exists.
For google, google itself has a very complex page structure on search results, I would not even attempt to do anything like this.
I would use qunit for testing javascript components on their own without dependencies.
If you are looking for another tool to do this task, I would recommend Selenium, which would do exactly what you want.
Good luck.
Do you want to test a website you own or a random live website?
If you want to test your own website
you can embed the live site in a iframe and perform actions in the user interface in your tests.
If you want to test live websites like google.com you need to do this server side since you can't access them from javascript/QUnit.
When you where the owner of a site like google.com you could do:
var submitted = false;
function starttests(){
if(!submitted)
test("testInput", function() {
expect(1);
submitted = true;
var dom = iframe.contentWindow || iframe.contentWindow.document;
jQuery(dom).find('input[type=text]').val("Testing google.com");
jQuery(dom).find('form').submit();
ok( true, "form submitted" );
});
else
test("testResult", function() {
var dom = iframe.contentWindow || iframe.contentWindow.document;
// Check for elements in dom.
});
}
iframe.onload(starttests);
iframe.src = "http://google.com";