From a1deeef71ce57b3289698b2d3dcca82ff2b62b82 Mon Sep 17 00:00:00 2001
From: mango <35127166+mangoGoForward@users.noreply.github.com>
Date: Fri, 14 Jan 2022 09:33:12 +0800
Subject: [PATCH] Revert "feat: support hide the authentication header in
 basic-auth"

---
 apisix/discovery/eureka/init.lua     |  12 +++-
 apisix/plugins/basic-auth.lua        |  16 +----
 conf/config-default.yaml             |   2 +-
 docs/en/latest/plugins/basic-auth.md |  13 ++--
 docs/zh/latest/plugins/basic-auth.md |   1 -
 t/plugin/basic-auth.t                | 100 ---------------------------
 6 files changed, 17 insertions(+), 127 deletions(-)

diff --git a/apisix/discovery/eureka/init.lua b/apisix/discovery/eureka/init.lua
index df72a5269e59..481e8e4b212a 100644
--- a/apisix/discovery/eureka/init.lua
+++ b/apisix/discovery/eureka/init.lua
@@ -19,6 +19,7 @@ local local_conf         = require("apisix.core.config_local").local_conf()
 local http               = require("resty.http")
 local core               = require("apisix.core")
 local ipmatcher          = require("resty.ipmatcher")
+local zlib               = require("zlib")
 local ipairs             = ipairs
 local tostring           = tostring
 local type               = type
@@ -161,10 +162,15 @@ local function fetch_full_registry(premature)
         return
     end
 
-    local json_str = res.body
-    local data, err = core.json.decode(json_str)
+    local encoding = res.headers["Content-Encoding"]
+    local res_body = res.body
+    if encoding == 'gzip' then
+        local stream = zlib.inflate()
+        res_body = stream(res_body)
+    end
+    local data, decode_err = core.json.decode(res_body)
     if not data then
-        log.error("invalid response body: ", json_str, " err: ", err)
+        log.error("invalid response body: ", res_body, " err: ", decode_err)
         return
     end
     local apps = data.applications.application
diff --git a/apisix/plugins/basic-auth.lua b/apisix/plugins/basic-auth.lua
index 25183899f519..5e780566310e 100644
--- a/apisix/plugins/basic-auth.lua
+++ b/apisix/plugins/basic-auth.lua
@@ -30,12 +30,7 @@ local consumers_lrucache = core.lrucache.new({
 local schema = {
     type = "object",
     title = "work with route or service object",
-    properties = {
-        hide_auth_header = {
-            type = "boolean",
-            default = true,
-        }
-    },
+    properties = {},
 }
 
 local consumer_schema = {
@@ -44,10 +39,6 @@ local consumer_schema = {
     properties = {
         username = { type = "string" },
         password = { type = "string" },
-        hide_auth_header = {
-            type = "boolean",
-            default = true,
-        }
     },
     required = {"username", "password"},
 }
@@ -181,11 +172,6 @@ function _M.rewrite(conf, ctx)
         return 401, { message = "Password is error" }
     end
 
-    -- 5. hide `Authentication` header if `hide_auth_header` is `true`
-    if conf.hide_auth_header == true then
-        core.response.set_header("Authentication", "")
-    end
-
     consumer.attach_consumer(ctx, cur_consumer, consumer_conf)
 
     core.log.info("hit basic-auth access")
diff --git a/conf/config-default.yaml b/conf/config-default.yaml
index e1ae17912921..c0f8837ff912 100644
--- a/conf/config-default.yaml
+++ b/conf/config-default.yaml
@@ -306,7 +306,7 @@ etcd:
 #  eureka:
 #    host:                        # it's possible to define multiple eureka hosts addresses of the same eureka cluster.
 #      - "http://127.0.0.1:8761"
-#    prefix: /eureka/
+#    prefix: /eureka/v2/
 #    fetch_interval: 30           # default 30s
 #    weight: 100                  # default weight for node
 #    timeout:
diff --git a/docs/en/latest/plugins/basic-auth.md b/docs/en/latest/plugins/basic-auth.md
index 9f7ce861db65..e618a58a8500 100644
--- a/docs/en/latest/plugins/basic-auth.md
+++ b/docs/en/latest/plugins/basic-auth.md
@@ -39,11 +39,10 @@ For more information on Basic authentication, refer to [Wiki](https://en.wikiped
 
 ## Attributes
 
-| Name             | Type    | Requirement | Default | Valid | Description                                                                                                                                                      |
-| --------         | ------  | ----------- | ------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| username         | string  | required    |         |       | Different `consumer` should have different value which is unique. When different `consumer` use a same `username`, a request matching exception would be raised. |
-| password         | string  | required    |         |       | the user's password                                                                                                                                              |
-| hide_auth_header | boolean | optional    | true    |       | Whether to return the Authentication response headers to the client.                                                                                             |
+| Name     | Type   | Requirement | Default | Valid | Description                                                                                                                                                      |
+| -------- | ------ | ----------- | ------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| username | string | required    |         |       | Different `consumer` should have different value which is unique. When different `consumer` use a same `username`, a request matching exception would be raised. |
+| password | string | required    |         |       | the user's password                                                                                                                                              |
 
 ## How To Enable
 
@@ -130,8 +129,8 @@ hello, world
 ## Disable Plugin
 
 When you want to disable the `basic-auth` plugin, it is very simple,
-you can delete the corresponding json configuration in the plugin configuration,
-no need to restart the service, it will take effect immediately:
+ you can delete the corresponding json configuration in the plugin configuration,
+  no need to restart the service, it will take effect immediately:
 
 ```shell
 $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
diff --git a/docs/zh/latest/plugins/basic-auth.md b/docs/zh/latest/plugins/basic-auth.md
index f7715bef2a4f..667721bd7ede 100644
--- a/docs/zh/latest/plugins/basic-auth.md
+++ b/docs/zh/latest/plugins/basic-auth.md
@@ -43,7 +43,6 @@ title: basic-auth
 | -------- | ------ | ------ | ------ | ------ | ------------------------------------------------------------------------------------------------------------------ |
 | username | string | 必须   |        |        | 不同的 `consumer` 对象应有不同的值,它应当是唯一的。不同 consumer 使用了相同的 `username` ,将会出现请求匹配异常。 |
 | password | string | 必须   |        |        | 用户的密码                                                                                                         |
-| hide_auth_header | boolean | 可选    | true   |       | 是否将 Authentication 响应头返回给客户端.                                                                                             |
 
 ## 如何启用
 
diff --git a/t/plugin/basic-auth.t b/t/plugin/basic-auth.t
index 5c06e2ca7e83..a780f3b618f8 100644
--- a/t/plugin/basic-auth.t
+++ b/t/plugin/basic-auth.t
@@ -395,103 +395,3 @@ GET /t
 GET /t
 --- no_error_log
 [error]
-
-
-
-=== TEST 15:  hide auth header = false
---- config
-       location /t {
-           content_by_lua_block {
-               local t = require("lib.test_admin").test
-               local code, body = t('/apisix/admin/consumers',
-                   ngx.HTTP_PUT,
-                   [[{
-                       "username": "foo",
-                       "plugins": {
-                           "basic-auth": {
-                               "username": "foo",
-                               "password": "bar",
-                               "hide_auth_header": false
-                           }
-                       }
-                   }]],
-                   [[{
-                       "node": {
-                           "value": {
-                               "username": "foo",
-                               "plugins": {
-                                   "basic-auth": {
-                                       "username": "foo",
-                                       "password": "bar",
-                                       "hide_auth_header": false
-                                   }
-                               }
-                           }
-                       },
-                       "action": "set"
-                   }]]
-                   )
-
-               ngx.status = code
-               ngx.say(body)
-           }
-       }
---- request
-GET /t
---- error_code: 200
---- response_body
-passed
---- no_error_log
-[error]
-
-
-
-=== TEST 16: enable basic auth plugin using admin api
---- config
-    location /t {
-        content_by_lua_block {
-            local t = require("lib.test_admin").test
-            local code, body = t('/apisix/admin/routes/1',
-                ngx.HTTP_PUT,
-                [[{
-                    "plugins": {
-                        "basic-auth": {}
-                    },
-                    "upstream": {
-                        "nodes": {
-                            "127.0.0.1:1980": 1
-                        },
-                        "type": "roundrobin"
-                    },
-                    "uri": "/hello"
-                }]]
-                )
-
-            if code >= 300 then
-                ngx.status = code
-            end
-            ngx.say(body)
-        }
-    }
---- request
-GET /t
---- response_body
-passed
---- no_error_log
-[error]
-
-
-
-=== TEST 17: verify with hide auth header
---- request
-GET /hello
---- more_headers
-Authorization: Basic Zm9vOmJhcg==
---- response_body
-hello world
---- response_headers_like
-Authentication:
---- no_error_log
-[error]
---- error_log
-find consumer foo