Step 2: Testing WAF

To ensure that WAF can forward your website requests normally, test WAF locally after you add the domain to WAF.

Before testing WAF, ensure that the protocol, address, and port number used by the origin server (for example, www.example5.com) are correct. In addition, if Client Protocol is set to HTTPS, ensure that the uploaded certificate and private key are correct.

Prerequisites

A domain name has been added to WAF.

Constraints

A CNAME record is generated based on the domain name. For the same domain name, the CNAME records are the same.

Connecting a Domain Name to WAF Locally

  1. Obtain the CNAME record.

    • If you are adding a domain name, perform the following operations to obtain the CNAME record of the domain name after configuring the basic information about the domain name:

      Click Copy to obtain the CNAME record of the domain name. See Figure 1 or Figure 2.

      Figure 1 Connecting a domain name to WAF (proxy used)
      Figure 2 Connecting a domain name to WAF (no proxy used)
    • If you have added a domain name, perform the following steps to obtain the CNAME record of the domain name:
      1. Go to the Website Settings page by following the steps shown in Figure 3.
        Figure 3 Accessing to the Website Settings page
      2. In the row of the desired domain name, under the Protected Website column, click the domain name you want to test.
        Figure 4 Basic Information
      3. In the CNAME row, click to copy the CNAME record.

  2. Ping the CNAME record and record the corresponding IP address.

    Use www.example5.com as an example and its CNAME record is xxxxxxxdc1b71f718f233caf77.waf.huaweicloud.com.

    Open the CLI and run the ping xxxxxxxdc1b71f718f233caf77.waf.huaweicloud.com command to obtain the WAF back-to-source IP address. As shown in Figure 5, the WAF back-to-source IP address is displayed.
    Figure 5 Ping CNAME

  3. Add the domain name and WAF back-to-source IP address to the hosts file.

    1. Use a text editor such as Notepad or Notepad++ to open the hosts file. Generally, the hosts file is stored in the C:\Windows\System32\drivers\etc\ directory.
    2. Add the WAF back-to-source IP address obtained in Step 2 and protected domain name to the hosts file. Adding a record shows an example.
      Figure 6 Adding a record
    3. Save the hosts file and ping the protected domain name on the local PC.
      Figure 7 Pinging the domain name

      It is expected that the resolved IP address is the WAF back-to-source IP address obtained in Step 2. If the resolved IP address is the origin server address, run the ipconfig/flushdns command in the Windows operating system to flush the DNS cache.

Checking Whether WAF Forwarding Is Normal

  1. Clear the browser cache and enter the domain name in the address box of a browser to check whether the website can be accessed.

    If the domain name resolves to the back-to-source IP address of WAF and WAF configurations are correct, the website can be accessed.

  2. Simulate simple web attack commands.

    1. Set the mode of Basic Web Protection to Block. For details, see Enabling Basic Web Protection.
    2. Clear the browser cache, enter the test domain name in the address bar, and check whether WAF blocks the simulated SQL injection attack at the domain name. Figure 8 shows an example.
      Figure 8 Request blocked
    3. In the navigation pane, choose Events to view test data. Figure 9 shows an example.
      Figure 9 Viewing test data