Intercepting external redirections with Cypress - cypress

Here is my test scenario:
The user opens a page in my application, fills in some details in a form, and then clicks the button in the form.
A third-party library triggers a redirect to an external website to validate some information. After the validation is complete (this validation takes place in a single page), the script on the external site redirects the user back to my application with a custom URL.
I know that what I described above is similar to an oauth flow, but for something different.
So I know that it is not possible to test external websites with Cypress. As a workaround, I am thinking of intercepting the redirect that is triggered by the button click and manually processing the external site with cy.request. But I am getting nowhere with intercepting the redirect after the button click event. How can I use cy.intercept to get the URL that is requested after the button is clicked?
The second question is that the page I will be working on with 'cy.request' redirects to my app with a custom URL. So I need to intercept this redirect as well to continue testing with the relevant page in my app.

Related

How can i bybass service worker cache?

I have a progressive web appliacation. on the home page i have a loging modal. If a user logs in the application reloads and now instead of the login button the server renders the user profile. now the problem am experiencing is that when i implemented the pwa, It caches the homepage and everything in it so the new page from the server is not rendered after the user logs in.
My application backend is in Nodejs(REST API) and is use javascript to consume the api but i use ejs to render the pages. How can i solve this?. For now i decided not to cache the homepage where i have the login modal. After doing this i realized the application is now not meeting PWA installation requirements.
You can cache everything in the service worker.
When you need to display different content for an authenticated user vs unauthenticated user you can render that as needed either in the UI code or even in the service worker.
A common example would be to show/hide the login, logout and profile link in the header. This is all doable with a few lines of code as the page is loaded.
These examples are mostly classList.[add|remove|toggle]. The profile might use a simple template and setting the innerHTML of a wrapper.
It is not that complicated in the end, I do this all the time for applications.
It sounds like you shouldn't configure your service worker to cache your normal HTML. Instead, you can use a service worker that will always go to the network when online, and will display custom "Sorry, you're offline" HTML when there's a navigation request that fails.
Here's a live example of following this pattern:
https://googlechrome.github.io/samples/service-worker/custom-offline-page/
Doing this will is sufficient to meet the "add to homescreen" PWA installation requirements.

Laravel 6 Prevent restricted actions which are registered after logout

I'm using laravel/ui for authentication, let's say i opened my website in two separate tabs.
After i logout from one tab, if i click let's say delete blog button on other tab,
it takes me to login page as i'm using auth middleware, after which if i login and my delete action runs.
How to prevent this, i only want delete action to run when user is logged in and in the above case, after user logs in, i don't want to perform delete action straight away, user needs to click delete button again.
There are several solutions:
The best practice would be to change the delete request type to POST. Check here how to correctly use HTTP methods
In your Auth middleware, always redirect the user to some landing page.
I would strongly advise changing the request type. Once, I had to help to restore an IT system where some smart arse ran script to follow all links in an internal website and fetch all pages. Delete operations were implemented with the GET method.

Binding Form Data on Browser Back Spring MVC

I'm Developing a application using Spring MVC + Hibernate. So It have a function that have a confirmation screen before complete the task.
In here After submit the main input form it creates a form submit. Then it redirect to confirmation screen and ask for users to review it. after reviewing user can proceed it for last step.
If user want to change values then i put a back button on confirmation.
back button manually and bind all the data and redirect it to first page. It is working.
But i want to know how to bind the data back to first form when user press browser back button ?
Sorry about my poor English.

failed to authorize twitter when trying to authorize app with windows phone 8/8.1

I've got a windows phone 8/8.1 app which contains a page with an embedded web browser on it. I build a list of articles extracting information from the website and all of this works fine but note that I only use this web browser to display an article when a user has clicked on the item in my list.
The article in question provides a button to allow user to leave comments via twitter. At the bottom of each article there is a "Twitter Log in" button. When I click on it, it brings me to the authorizing page and it displays the news website as the app I want to authorize.
After entering my twitter credential and clicking on the "Authorize App", I get the following error:
Exception of type 'Microsoft.Phone.Controls.WebBrowserNavigationException' was thrown.
Then a Twitter webpage gets displayed display the following:
There is no request token for this page. That's a special key we need from applications asking you to use your Twitter account. Please go back to the site or application that sent you here and try again. It's probably just a mistake.
It definitely authenticated me as I can see my Twitter account picture but it failed to authorize the app.
I understand that my app is not the original website as it is a wp8/8.1 app but what I'm calling in the web browser is the page that contains all the original code from the news website and therefore you would assume everything would work as if I was calling the website directly from a browser.
If I call the website from the browser that comes with wp8/8.1, it works as expected!! Strangely enough they have the same functionality but using facebook and this works as expected.
I've had a look at html the "twitter authorized page" when called from my phone and when called directly from my web browser on my laptop and while I can clearly see the form contains an hidden field for authenticity_token with a value and a oauth_token with another value, they do differ.
I don't know if they're suppose to be identical but as I said, I don't understand why this wouldn't work as when I display the article in the embedded web browser, you'd assume that everything else that goes on after this would behave as it would in a regular web browser and when this 'authorize app' button is clicked, you'd assume that all values would be passed as normal and the app would get authorized but nope!!
Any suggestions on how I could possible resolve this problem?
Thanks.
I can't really tell what's going on, but it looks like you would have to implement Twitter OAuth. Luckily for you there is already a library that can do that - https://github.com/konradbartecki/TwitterAutherino
I am the author of this library, so let me know if you need some support or non-existent features.

How can I trigger a javascript Facebook authentication dialog box on an anchor tag?

I have a simple rating system that logged in users can just click and it updates asynchronously.
However, I still want non-logged in users to see the rating mechanism (let's say a simple "up" arrow) but trigger the Facebook authentication popup when they click the link.
Can you help? I have the regular fb:login button working just fine. But how can I trigger this action on a regular anchor tag (in addition to the fb:login button).
You need to call the FB.login method
https://developers.facebook.com/docs/reference/javascript/FB.login/
You can bind this to the button click for non logged in users, on the callback you can register the original rating action or refresh the page.

Resources