Hi, I’m Milo, a test development blogger, the world is big, you should check it out!

Welcome everyone to pay attention to my public number: test development pit goods.

review

There was a github login last week and it didn’t go down well. So let’s continue to refine the use cases this week.

digression

In fact, although I am working on such a test platform, there are some problems, as Fan said:

  • Its own platform didn’t land

  • Semi-finished products

  • I didn’t use it myself

    Indeed, while the previous company supported more than 90 percent of the line of business, it incorporated a lot of corporate content such as GRPC, microservice autoaddressing, YAPI, internal publishing systems, data factories, etc.

    The project is exactly the same as it was then (implemented in another language), but it’s not quite the same.

    In order to better support the development of the platform, plus time, SO I decided to choose a small, but comprehensive project to test.

    I needed to find an open source Java project for subsequent coverage related features, so I found it, a blogging system based on SpringBoot + Vue + elemental-UI:

Generally, such open source projects are almost semi-finished products, but as long as they have a good login (token/cookie mechanism), plus a part of the CRUD function.

I have deployed this address to my own server, so I can test this service directly in the future, but first we need to carry out the interface data in it.

The service address: http://47.112.32.195:8081/index.html

Began to study

I glanced through its authentication module, and it uses Spring-Security, which is a brand new area that I haven’t touched.

But let’s not panic. Let’s see how his login works.

As you can see, it is a POST request from the form, and the content returned has no information such as token. What is to be done? Don’t be afraid, we do such tools, not afraid of more special cases, afraid of less special cases, resulting in poor compatibility!

Let’s debug the login interface to make sure:

To find the reason

Project address: github.com/lenve/VBlog…

We’ll pull the project locally github.com/lenve/VBlog… Debug finds that username is an empty string.

There’s a good chance that our requests are in the wrong posture. What should we do?

Let’s take a look at how our requests method is encapsulated.

As you can see, our body is a string, but if we want to request a form, the body needs to be a dict.

The transformation is as follows:

If the content-type has a form in it, then we’ll change the body to a dict (via json.loads).

After the transformation, experiment:

In this way, we support HTTP requests for JSON and form, and as for the file type, we will continue to explore.

But what about tokens?

Don’t worry, let’s switch to the Cookietab, and you can see that the Cookie has the JSESSIONID in it, so that we can continue with our subsequent login requests. Not much different from token.

Remember the optimization point, when the request Type is switched to form/ JSON automatically change the content-type, so the experience is better!

In the next article, we start writing data initialization. For example, if I want to query an article and need to log in first, the data I need to initialize is the JSESSIONID mentioned above.

The document address