Feedback from mocking with Restito - java

When mocking REST with Restito, is it possible to get some feedback when you mocked something incorrectly? I mean, if the request has already been sent to the stubserver from the implementation, couldn't it just record that request and present it for me?
Because sometimes it requires a lot of struggling to get the exact match of everything and it would be helpful to get some feedback when working with it.

You could set logging level to DEBUG and then you see all the requests to thestub server.

Related

Unable to signup using Keycloak through Cypress

In my application, user management is done through Keycloak. While testing my application end-to-end through Cypress, I came across an issue. When I sign up a user, it gives the following error:
We're sorry. An error has occurred, please login again through your application.
Cypress is adding something to a generated URL after I click the submit button, which is causing this issue. The same scenario tested through Protractor ran fine. I have noticed Cypress is appending session_code to the request URL. While doing manual testing, I don't get session_code.
Below is the URL generated through Cypress:
.../login-actions/registration?session_code=LsZbmsVVLwEH9s-xwFJ2JdDtaCu1_xzqAGOQCpjxGJI&execution=06fac3bb-fb19-474b-8659-2572586ae371&client_id=web_app&tab_id=PSlmfgdv0ls
Where as a manually generated URL is like following:
.../login-actions/registration?client_id=web_app&tab_id=PSlmfgdv0ls
My application backend is Spring Boot and the front-end is in React and Next.js.
It would be really helpful if anyone could guide us through this issue. Please let me know if you need more information about our application.
The Keycloak Authenticator documentation explains that the authenticate method checks the current HTTP request to determine if authentication requirements have been satisfied, and, if not, a challenge response is sent back. If the challenge response itself is authentication, then you'll see a URL with the session_code parameter.
It goes on to say that session_code, in the first URL example, pertains to the code generated from AuthenticationFlowContext.generateAccessCode(), which further explains:
String generateAccessCode()
Generates access code and updates clientsession timestamp. Access codes must be included in form action callbacks as a query parameter.
However, the "manually" generated URL, that does not include the session_code parameter, seems to indicate that the initial registration of the client has been successful and a client configuration endpoint is being used to make a GET request - a client read request - and all is well. Everything works fine.
Therefore, it seems that Cypress is being sent a challenge response (and potentially exposing a security flaw in your application). Possible reasons for this might be further explained within Cypress's documentation on Web Security.
Common Workarounds might provide you with a remedy, or, if all else fails, you might try Disabling Web Security for testing purposes as well.

Jsoup, Reddit, OAuth2, and 429 HTTP Errors

So I'm trying to write an executable JAR for a small subreddit I run.
I have a post that Jsoup connects to and reads all the URLs on that page. In another method, it then connects to all those URLs (that are just comments on the post) and gets the HTML from the comments and saves them to a HashMap.
This is great however I am getting a 429 HTTP Error. So to resolve this, I added a short 5 second wait. Now I'm getting a SocketTimeoutException "Read timed out". Once I lowered the time down to 3 seconds, I was bouncing between the two.
Now I run a few Reddit bots with Python and I'm able to make a lot more requests than what I'm doing here. I actually have a single bot that makes thousands of requests every minute. So I know it's possible to make these requests.
My question essentially is, how am I able to make multiple requests to Reddit and avoid the 429 HTTP Error? I'm using Jsoup to connect and read the HTML.
While I'm sure connecting to Reddit via. their OAuth2 API will fix the issues, I have no idea how to actually use OAuth2 in Java (I actually use a wrapper in Python so it's fair to say I don't know at all) and I don't know how to then use that with Jsoup.
My question essentially is, how am I able to make multiple requests to Reddit and avoid the 429 HTTP Error?
You answer this yourself:
While I'm sure connecting to Reddit via. their OAuth2 API will fix the issues,
As specified in the API documentation, you get twice as many requests per second if authenticated using OAuth.
Have you looked around for examples on how to handle OAuth flows in Java?
You might also find it easier to use one of the wrapper libraries for Java, instead of handling all this yourself.
Just set header and you can easily pass it
User-Agent: super happy flair bot by /u/spladug

android check if request is coming from my app

The application I'm creating is supposed to allow client to send some feedback to server, so I make a simple httprequest with my feedback and other information in it, but I wanna make sure that request can only come my application, the rest should be rejected. So what are my choices?
Thank you for your helpful directions in advance.
P.s: I'm not asking for code, just the best practice.
I have looked for the same thing and what is possible is to force the app users to sign in with their Google account and then you can get verification via tokens that the call came from your app as described here:https://developers.google.com/identity/sign-in/android/backend-auth
That there isn't an option without having users sign in is disappointing.

trello oauth failed to redirect me to oauth_callback, and keeping redirect me to oob

I'm aware of this question, but it seems I still have this problem, I used
https://trello.com/1/appKey/generate
to generate my key and secret, and fill them into scribe library, the example seems right, but after I append
&oauth_callback=http%3A%2F%2Fexample.com%2Fapi
to
service.getAuthorizationUrl(requestToken)
trello keeping redirect me to something like
https://trello.com/oob?oauth_token=7ad36dcd7ca713648ed3549c2f1828c5&oauth_verifier=5b0dc2b64d0b7ee08c56a9b1f30f8880.
I'm not sure what I'm missing, does trello requires some application registration?
ok, I finally figured it out, it's scribe library example's fault that didn't make it clear: we should call callback and provide with callback to user's site before build the service

Spring MVC forward to another URL

I create a web-application with Spring 4. It must work as proxy for internal resources of our company.
When it receives user requests, it analyses its correctness and user privilegies, and if everything is correct, gives user the result.
So, is it possible to do forward request to page like http://xxxxx.com:8983/solr?
If yes, show the example, please
So that user writes url of my application and sees the page http://xxxxx.com:8983/solr
P.S. I tried to find it in google, but everywhere were answers about redirect but not forward
Well, I think there are multiple ways of dealing with this. But my gut feeling is that you're going to have to write some code yourself.
Basically, I would use HttpClient to make a request to your proxied website, take the input stream from the httpclient connection and stream it to the output stream of your spring application response.
You could handle all this interaction in the controller itself, but I think using a specialized ViewResolver might be better.
Have you tried:
return "forward:/page/section/";

Categories

Resources