Programatically logging in as admin user on Drupal 8, using Cypress - drupal

Trying to test some content creation test using cypress on Drupal 8 site, however having trouble logging in programatically as recommended on Cypress's doc
(https://docs.cypress.io/guides/getting-started/testing-your-app.html#Logging-in)
Followed the steps on this site (https://sevaa.com/blog/2018/10/end-to-end-testing-with-drupal-and-cypress/), but when I ran cy.login(username, pwd)(I'm using actual value, not undefined variable...), always get 403 forbidden error.
Also, while I'm able to login using UI and I can navigate admin section of Drupal by clicking on links, but soon as I use cy.visit('/admin/content') I get 403 error...
Has anyone successfully bypass this 403 errors by logging in programatically?
And if so, how did you manage to do so?

I'd recommend installing Cypress-drupal node package. After that you can login with simple cy.drupalLogin('admin', 'admin') command.

Related

I'm trying to send a form on my wordpress website using ajax, but its an error 500

The form is created using Contact Form 7, but the submit action is made with AJAX and a file php which made a database conection, the error return: 500 (Internal Server Error) on php file and: Uncaught TypeError: $(...).AjaxDebug is not a function on AJAX function.
In the debug file generated by WP there is nothing related with this error.
someone can help me to understand this problem?
I disabled the plugins one by one, hoping for the problem is a conflict, but nothing change.
you clean the cache?! use a plugin like Super Cache good luck

Drupal - Disable SAML login in local instance

I am very new to Drupal. I have done the local setup and the front end is working fine. Now I need to login to the admin interface. Seems like there is a SAML configuration and when I try to access the /user/login page it is showing the following error :
The website encountered an unexpected error. Please try again later.
I can see there is one simplesaml folder in the codebase and I think this is handling the SAML login. Now in the local setup, I don't need to use SSO, but not sure how to disable this extension. I have checked in the core.extension.yml, but the fllowing extensions set to 0 there and hence I think this is not activated.
basic_auth: 0
externalauth: 0
simplesamlphp_auth: 0
Also in my local configuration settings.local.php, it is set as false:
$config['simplesamlphp_auth.settings']['activate'] = FALSE;
It will be very much helpful if somebody can guide me in the right direction. I have access to the database, but not sure where I need to make changes. This might be a simple thing, but I am blocked here.
The Error I am seeing the logs is like this :
Uncaught PHP Exception SimpleSAML\Error\Exception: "Could not find the metadata of an IdP with entity ID 'localhost:default:entityId'" at /vendor/simplesamlphp/simplesamlphp/modules/saml/lib/Auth/Source/SP.php line 317
You can login to Drupal using a console command.
Open a terminal, navigate to the project folder like
cd ~/project/my-project/web/
Then run
drush uli
the output will be a one time login link.

Issue installing R facebook HTTP 400

I am trying to install the facebook API with R. I have seen that a few people were also having trouble but I did not find the same issues than me.
I have gotten the library but when I use the function
fb_oauth <- fbOAuth(...
and after putting the URL on Facebook App Settings: http://localhost:1410/, I press enter and get the following message on the facebook page :
"Can't Load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings."
And on R :
Authentication complete.
Error in oauth2.0_access_token(endpoint, app, code = code, user_params =
user_params, :
Bad Request (HTTP 400). Failed to get an access token.
I have tried several things but nothing seems to have worked. Maybe I made a mistake when putting the URL but then I don't know where else I should put it...
For the fb_oauth I have tried both with extended_permissions False and True
and for app_id and app_secret I have used the info of the page : screen shot
For the URL I have clicked on settings > Add Platform > Website > and then copied the URL second screenshot
I really need this to work so I would appreciate so much if you could help me
I have finally found how to fix the problem myself !
Just needed to create a Facebook login with the correct URl and it worked !
Adding a platform is not sufficient.

Impletmenting a custom meteor accounts package

I have been writing my own meteor accounts package and I seem to be missing something. I am not getting any errors in the browser or in the terminal so it's difficult for me to troubleshoot. The only error I get is from the accounts-ui package itself which is saying 'No login services configured.' The code can be seen at https://github.com/khamoud/meteor-accounts-stripe if anyone could take a look. Thanks in advance.
I created a accounts package myself a while ago and my advice would be to stick to whatever is done in the base accounts packages of the same service (in this case OAuth 2 it looks like) as closely as possible. I can see you have done that but there are minor differences.
I downloaded your package and tried it out myself. While I can't get it working (I haven't used the Stripe API so I wont be digging into it completely) I think I can make more progress than you have had.
First of all I don't get a 'No login services configured' error. Did you add your package? I did 'meteor add accounts-ui', created a packages folder in the my project's root and pasted your package folder into it, renamed it 'accounts-stripe' and did 'meteor add accounts-stripe'.
I then added a {{loginButtons}} helper to the page. With this I got the configure Stripe login buttons but it wouldn't open a pop-up when I clicked on it. I got an error message in the js console 'Uncaught Error: Duplicate service: stripe'. The problem seems to be you have the line:
Accounts.oauth.registerService('stripe');
in both accounts_stripe.js and stripe_client.js. Removing it from stripe_client.js fixed it for me. I could then add my API keys from stripe.
The next problem is once these are submitted you store them in 'clientId' in stripe_configure.js but then retrieve them using appId from the config object in stripe_client.js and stripe_server.js. I noticed this because the login URL in the pop-up after submitting the API keys had a undefined client_id. Changing 'clientId' to 'appId' in stripe_configure.js will fix that.
Unfortunately it still doesn't work. I get
{"error":{"message":"No application matches the supplied client identifier"}}
from the pop-up window. This could be for any number of reasons, perhaps I submitted the wrong thing in the API keys window, maybe it's because I'm using a test project on Stripe, or maybe you have implemented the login workflow incorrectly. A quick google of the Stripe OAuth docs suggests that I have submitted the wrong things for the client_id and secret. Like I said I haven't used the Stripe API before.
I hope I have got you started on fixing it though.

Redirect modules

How can I get a module to redirect if a user doesn't have the correct permissions to view it instead of getting the usual "Access denied. You are not authorized to access this page." message?
If it is a module you are writing yourself use the goto function of Drupal
http://api.drupal.org/api/function/drupal_goto
If you are not writing it yourself then it's a bit tougher, you can set the error redirects with Drupal and some modules however for a specific module I think you might have to go in and patch it in some way.
pretty much anything you wanna do to modify drupal stock behaviour can be handled via hook_nodeapi
Custom Error provides the ability to easily customize 403 and 404 error messages. With that, you could use drupal_goto() to automatically redirect users, or drupal_get_destination() to build a login link that will return the user to the page they attempted to view.
For more general, login-specific functionality, you might check out LoginToboggan.
The source code for both modules will also include useful examples of how to approach this problem space if you do not want the overhead or external dependency of a module.

Resources