Developer Test (3)-Penetration testing of Springcloud micro-service applications with precision testing tools

Source: Internet
Author: User
Tags joins spring initializr

1, micro-service introduction
 
MicroServices English Name Microservice,microservice schema mode is to organize the entire Web application into a series of small Web services. These small Web services can be compiled and deployed independently, and communicate with each other through their exposed API interfaces. They work together to provide functionality to the user as a whole, but can run independently.
 
2. Introduction to Spring Cloud Project
 
Spring Cloud is a complete framework for implementing microservices based on spring boot. Components such as configuration management, service discovery, circuit breakers, only routing, micro-proxies, control buses, global locks, decision campaigns, distributed sessions, and cluster state management are provided for micro-service development.
 
3. Pre-preparation work
 
3.1 Configuring the JDK

 


 
3.2 Configuring Tomcat
 


3.3 Configuring Maven
 
Note: The idea tool for Jetbrain in this article is integrated with Maven, as shown in:
 

 
If you make changes, fill in the local maven actual path.
 
4. The Spring Cloud environment
 
Spring Cloud Source
IntelliJ Idea (hereinafter referred to as "idea")
Mysql
JDK8
Tomcat7
Maven
 
4.1 Installation Environment
 
Note: IntelliJ idea and JDK installation and installation packages are available on their own, nebula testing will provide MySQL and Nodejs installation packages, but must be provided that the user does not have installed MySQL and Nodejs on their own native computer.
 
4.1.1 Script One-click Install MySQL and Nodejs
 
1. Open the Tt_soft folder

 
2. Run as Administrator TeststarsSoftInstall.exe

 
3. Wait for automatic installation to complete, close the window

 
4. Start MySQL service with net start MySQL command

 
5. Use Node–v to view node version

 
5. Configure Spring Cloud
 
5.1 idea create Eureka service Registry
 
Hereinafter referred to as the "8000" project.
New project:

 
Idea creates a new spring boot project, selects Spring Initializr, and can be created and imported locally on Https://start.spring.io:

 
Modify group and other related information:

 
Note The version selection of Spring boot in the upper right corner:

 
Click to finish directly:

 
Here, a Springboot project is completed.
The next thing to do is to configure a Eureka service registry.
The pom.xml of this project adds the following:

<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter</artifactId></dependency>

Add @enableeurekaserver annotations and import to the startup code ... as follows:

package com.teststars.springclouddemo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@EnableEurekaServer@SpringBootApplicationpublic class SpringcloudDemoApplication {   public static void main(String[] args) {      SpringApplication.run(SpringcloudDemoApplication.class, args);   }}

Modify Application.properties (add Eureka.client.register-with-eureka=false and eureka.client.fetch-registry= False means not to allow the service center to register itself):
 

server.port=8000eureka.instance.hostname=localhosteureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.service-url.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

 
Start the Eureka server:

 
See the log below to indicate that the Eureka server started successfully:

 
To open Google Chrome (due to the default settings in idea), visit https://localhsot:8000/to see the microservices viewing panel:

 
At this point, the service registry is configured to complete and the service registration operation is followed.
 
5.2 Idea Create service provider
 
Hereinafter referred to as the "8001" project.
 
Create a eureka-client client that is the service provider client that provides some meta data to the registry, such as hosts and ports, URLs, home pages, and so on. Eureka server receives heartbeat messages from each client instance. If the heartbeat times out, the instance is typically removed from the registration server.
 
Create the project Springcloud-provider-demo as created above:
 
Add @enablediscoveryclient and import to the startup code ... as follows:

package com.teststars.springcloudproviderdemo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@EnableDiscoveryClient@SpringBootApplicationpublic class SpringcloudProviderDemoApplication {   public static void main(String[] args) {      SpringApplication.run(SpringcloudProviderDemoApplication.class, args);   }}

Modify Application.properties:

server.port=8001spring.application.name=springcloud-servereureka.client.service-url.defaultZone: http://localhost:8000/eureka/

Write a simple controller. Note the controller you write must be at the Startup class directory level or below. Otherwise it will not load.
In the project startup class, under the sibling directory, create a new package: Controller, add Class: HelloWorld, as follows:

package com.teststars.springcloudproviderdemo.controller;import org.springframework.web.bind.annotation.*;@RestControllerpublic class HelloWorld {    @GetMapping("/test/{id}")    public String test(@PathVariable String id){        return "hello"+id.toString();    }}

 
Start the project springcloudproviderdemoapplication;
 
Refresh the interface in the browser: Https://localhsot:8000/viewing the Eureka Information Panel service information, you can see that there is a 8001 service displayed:
 

 
Click the Green Font section in the image to display the following:

 
8001 interface After adding parameter/test/test access, note: Test can be any character, shown as shown:

 
5.3 Idea Create consumer
 
Hereinafter referred to as the "8002" project.
 
Here's how to create a re-import idea on Https://start.spring.io:
 



 
Pom.xml Add the following content:
 

<dependency>   <groupId>org.springframework.cloud</groupId>   <artifactId>spring-cloud-starter-ribbon</artifactId></dependency>

 
Modify Application.properties:
 

server.port=8002spring.application.name=springcloud-customereureka.client.service-url.defaultZone: http://localhost:8000/eureka/

The @enablediscoveryclient is added to the startup code, and the bean,resttemplate that joins Resttemplate is the class that spring uses to manipulate the rest resource, using the template mode. Note @loadbalanced that only this annotation can be used to integrate the Ribbon for resttemplate to achieve load balancing. When used with the Ribbon, the Eureka automatically maps the service name to the network address of the microservices. Enables scalability enhancements. As shown below:

package com.teststars.springcloudcustomerdemo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.client.loadbalancer.LoadBalanced;import org.springframework.context.annotation.Bean;import org.springframework.web.client.RestTemplate;@EnableDiscoveryClient@SpringBootApplicationpublic class SpringcloudCustomerDemoApplication {   public static void main(String[] args) {      SpringApplication.run(SpringcloudCustomerDemoApplication.class, args);   }   @Bean   @LoadBalanced   public RestTemplate restTemplate(){      return new RestTemplate();   }}

 
Write controller, here resttemplate.getforobject in the URL to Http://localhost:8001/test is also possible, but so the coupling degree is relatively high, If the address of the service provider has changed, the consumer will not be able to run properly. Since the ribbon is integrated, this can be replaced by a service name.
 
Create a new package under the sibling directory of the Project startup class: Controller, Add Class: Test, as follows:
 

package com.teststars.springcloudcustomerdemo.controller;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RestController;import org.springframework.web.client.RestTemplate;@RestControllerpublic class Test {    @Autowired    private RestTemplate restTemplate;    @GetMapping("/test/{id}")    public String test(@PathVariable String id){        return this.restTemplate.getForObject("http://SPRINGCLOUD-SERVER/test/"+id,String.class);    }}

 
Start the project springcloudcustomerdemoapplication;
 
Refresh page in browser: https://localhsot:8000/view Eureka Information Panel service information you can see one more service, as shown in the 8002 Green Fonts section:

 
Click the Green Font section in the Image:

 
Add parameter/test/aaa, note: AAA can be any character:

 
6. Test Project
6.1 Download tools and tools configuration
6.1.1 Download Nebula Test tool from official website: http://www.teststars.cc/
 

 
Download it for configuration later.
Configuration of the 6.1.2 Nebula test server
Ttlangage.config Configuration Item Description:

 
1. Run under the Nebula Test Server directory ThreadingTestServer.exe, in the bottom right of the chart to register information, view its time, nebula testing has a two-month experience, if more than two months, the occurrence of key expires, please contact the Nebula Test staff, and submit the service side of the serial code.
 

 

 

2, contact the Nebula staff to obtain the current server's Key.key file, replaced by the Nebula Server directory;
 
3, start the server directory ThreadingTestServer.exe will automatically open the ThreadingTestServerFront.exe under the sibling directory, see automatically pop up the following window, indicating that the connection is normal.
 

 
configuration of the 6.1.3 Nebula test client
Note: Nebula testing the connection to the online client requires access to port 17262/17263. Before logging in, you need to ensure that there are no restrictions on network connectivity.
Before opening the client, you need to modify the Server.cfg file under the Ttclient folder to configure the Localip entry as a native IP address that can communicate with the server properly. The reason for configuration Localip is that the client needs to receive dynamic data from the server and configure the local IP address server to transmit the data to the client.
 
After configuring the IP address, double-click Run Ttclient\tt.exe file to enter the Nebula test client. Select File, login, enter the IP address of the Nebula test server and your username and password to log in. As shown in the following:
 

 
6.1.4 Nebula Test Cloud reporting Platform service launch
 
1, run the Nebula Test Ttweb directory Bin\redis-2.4.5-win32-win64\32bit in the Redis-server.exe:

 
2, run the Nebula Test Ttweb directory Startttwebserver.bat:

 

 
Visit Web page report page IP address: 3000
 
6.2 Creating and compiling projects and versions
 
1. Login Client
 
2. Select the empty version to be inserted, the version is unlocked (unlock status: Right-unlock State)
 
3. Modify the Server.cfg configuration file under the Javaforwindows directory, [SERVER] IP fill in the actual IP address, modify the [property] field, and synchronize with the SERVER.CFG under the client directory:
 

 
4. Modify the Complierpath.xml configuration file in the Javaforwindows directory:
Multiple sub-modules can be added under the same version, i.e. Proname,proname cannot be duplicated, and multiple project paths can be configured under one submodule.
 
Proname: Sub-module name
 
Project_path: Test program source file path
 
Class_path: Test Program class file path
 
Note: Because project 8002 is associated with 8001, there is a need to compile 8001 and 80,022 modules. Such as:

 
5, modify the Javaforwindows directory under the Tt_windows folder Server.ini configuration file,
IP is set to the IP address where the client resides:
 

6. In the Javaforwindows file root directory, open the command line to run Autocompiler.jar to compile:
Jre\bin\java.exe-jar autocompile.jar–e D:\J2EE_Enterprise_key_64bit0814\CompileToolsPkg\javaForWindows
 
Note: The parameter after-E is the directory of the Complierpath.xml file.
The compilation succeeds as shown in:
 

 

 
7. View the data on the client, select the newly created empty version, and right click Reload version data.

 
Because the test needs to run the plug-in code (after the compilation is completed in the Java directory in the same layer generated Src-instru directory, Src-instru directory is compiled after the plug-and-install source);
What to do: First rename the Java directory under the source directory to Pre_java, and then name the compiled Src-instru directory java.
In order to make the function coverage visual View Code part of the normal display, you need to manually modify the source path: Right version, click Modify Source Path, select to Pre_java directory.

6.3 Pre-Test preparation
 
6.3.1 Adding a data transfer configuration file

 
Data transfer profiles are guaranteed to be run back to the nebula server. The configuration method is to create a new configuration file under the Usr/local/bin folder under the specific customer test environment Config.cfg file contents as follows:
 
State=1
ip= (IP value write Nebula Test server IP, note to capitalize)
(If the publishing environment is a Windows environment, you need to configure the above file in the C packing directory)
 
6.3.2 Agent Startup Project
 
There are two ways to start a project using the agent package provided by the Nebula test:
Adding agent parameters to the project startup item in the 6.3.2.1 Idea development tool
 
Note: The following configurations are required for 8001 projects and 8002 projects:

 
VM Options Add the following configuration, and the jar file is filled in by the absolute path of the agent unzip file provided by the Nebula test:

 
Modify click Apply, OK;
The operation of the plug-in code needs to add the jar package provided by the Nebula Test, need to modify the Pom.xml file to introduce the jar, add to two <dependencies>, add the following code:
 
Systempath by the absolute path of Javaparser-j2ee.jar and Jeromq-0.3.0-snapshot.jar:
 

 <dependency>   <groupId>com.zoa</groupId>   <artifactId>JavaParser-ZMQ</artifactId>   <version>1.0</version>   <scope>system</scope>   <systemPath>D:\J2EE_Enterprise_key_64bit0814\client\MQ\JavaParser-j2ee.jar</systemPath></dependency><dependency>   <groupId>com.zoa</groupId>   <artifactId>jeromq</artifactId>   <version>1.0</version>   <scope>system</scope>   <systemPath>D:\J2EE_Enterprise_key_64bit0814\client\MQ\jeromq-0.3.0-SNAPSHOT.jar</systemPath></dependency>

After the 8001 and 8002 projects have been modified, the idea runs 8000, 8001, and 8002 projects in turn, starting the project successfully such as:

 
 

Add the agent parameter to the start command of the 6.3.2.2 jar package
 
Start the normal 8000 project first;
 
The operation of the plug-in code requires the addition of the jar package provided by the Nebula test:
 
Idea directly introduces the jar package provided by the Nebula Test, as shown in the following:
 

 
 
 

After the introduction of the jar package, the 8001 and 8002 items are packaged in idea: Clean->package:



Next Open two dos windows, enter the following command with the agent parameter, Start 8001 and 8002 projects:

Java-javaagent:d:\0823zoa-agent-1.6.2\zoa-bootstrap-1.6.2.jar-jar d:\ Springcloud-provider-demo\springcloud-provider-demo\target\springcloud-provider-demo-0.0.1-snapshot.jar

Java-javaagent:d:\0823zoa-agent-1.6.2\zoa-bootstrap-1.6.2.jar-jar D:\springcloud-customer-demo\target\ Springcloud-customer-demo-0.0.1-snapshot.jar

D:\0823zoa-agent-1.6.2\zoa-bootstrap-1.6.2.jar =agent path;
D:\springcloud-provider-demo\springcloud-provider-demo\target\springcloud-provider-demo-0.0.1-SNAPSHOT.jar = project path; The following interface appears in

to indicate that the project started successfully:


6.3.3 Setting Cookies

Open Google Chrome (the default setting for idea is Google Chrome), Enter URL: http://localhost:8000 open Eureka Service registry; You can see that 8001 and 8002 are already displayed on the panel:



Click 8002 for the corresponding green font section into the 8002 corresponding interface:


1, after the project URL plus parameter teststars.jsp, access the page for cookie settings:
 

 
2, click Setcookie to set, set the Success page as follows:

 
Note: In order to differentiate the test, the user name set is consistent with the current login user name of the Nebula client.
To view the console printing information, the username setting is successful:
 

 
7. Test results
7.1 oscilloscope Waveform Display
Check the test cases first, and then click on the start to do the appropriate testing work, when testing the oscilloscope can receive dynamic data and the way the waveform is displayed.
 

 
Refresh the data because 8002 is associated with 8001, so here you can see that the test 8002,8001 is also covered:

 

 

is a spring cloud micro-service architecture two nodes of the call graph, when accessed from the first layer of the portal component, the Ingress component back to the next layer of nodes, the running thread of the latter node automatically takes the user information of the previous node, and joins to the second layer of node running line program, This allows the data to be received from two nodes by means of a precision test oscilloscope (the login user ID and the request identity are consistent). And when multiple users access the distributed application at the same time, the data from different users will be automatically separated and routed to the corresponding oscilloscope and finally corresponding to the use case.

Developer Test (3)-Penetration testing of Springcloud micro-service applications with precision testing tools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.