This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new fd42a444e fix: handle error in GetAccessKeyStorages and return it 
(#3016)
fd42a444e is described below

commit fd42a444e777aa6cdfc951b8904e225bc3ecd95a
Author: Xibei <[email protected]>
AuthorDate: Mon Sep 8 01:16:29 2025 +0800

    fix: handle error in GetAccessKeyStorages and return it (#3016)
    
    * fix(auth): handle error in GetAccessKeyStorages and return it
    
    * fix(auth): update Test_getAccessKeyPairFailed to assert error presence 
and message
---
 common/extension/auth.go                  | 13 +++++++++----
 filter/auth/default_authenticator.go      |  5 ++++-
 filter/auth/default_authenticator_test.go | 10 ++++------
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/common/extension/auth.go b/common/extension/auth.go
index 27ac62e69..430e0697f 100644
--- a/common/extension/auth.go
+++ b/common/extension/auth.go
@@ -17,6 +17,10 @@
 
 package extension
 
+import (
+       "errors"
+)
+
 import (
        "dubbo.apache.org/dubbo-go/v3/filter"
 )
@@ -47,9 +51,10 @@ func SetAccessKeyStorages(name string, fcn func() 
filter.AccessKeyStorage) {
 
 // GetAccessKeyStorages finds the storage with the @name.
 // Panic if not found
-func GetAccessKeyStorages(name string) filter.AccessKeyStorage {
-       if accessKeyStorages[name] == nil {
-               panic("accessKeyStorages for " + name + " is not existing, make 
sure you have import the package.")
+func GetAccessKeyStorages(name string) (filter.AccessKeyStorage, error) {
+       f := accessKeyStorages[name]
+       if f == nil {
+               return nil, errors.New("accessKeyStorages for " + name + " is 
not existing, make sure you have import the package.")
        }
-       return accessKeyStorages[name]()
+       return f(), nil
 }
diff --git a/filter/auth/default_authenticator.go 
b/filter/auth/default_authenticator.go
index 9cceede2d..a4d149646 100644
--- a/filter/auth/default_authenticator.go
+++ b/filter/auth/default_authenticator.go
@@ -123,7 +123,10 @@ func (authenticator *defaultAuthenticator) 
Authenticate(inv base.Invocation, url
 }
 
 func getAccessKeyPair(inv base.Invocation, url *common.URL) 
(*filter.AccessKeyPair, error) {
-       accessKeyStorage := 
extension.GetAccessKeyStorages(url.GetParam(constant.AccessKeyStorageKey, 
constant.DefaultAccessKeyStorage))
+       accessKeyStorage, err := 
extension.GetAccessKeyStorages(url.GetParam(constant.AccessKeyStorageKey, 
constant.DefaultAccessKeyStorage))
+       if err != nil {
+               return nil, err
+       }
        accessKeyPair := accessKeyStorage.GetAccessKeyPair(inv, url)
        if accessKeyPair == nil || IsEmpty(accessKeyPair.AccessKey, false) || 
IsEmpty(accessKeyPair.SecretKey, true) {
                return nil, errors.New("accessKeyId or secretAccessKey not 
found")
diff --git a/filter/auth/default_authenticator_test.go 
b/filter/auth/default_authenticator_test.go
index 8e074b5e6..dd24d63a5 100644
--- a/filter/auth/default_authenticator_test.go
+++ b/filter/auth/default_authenticator_test.go
@@ -106,10 +106,6 @@ func Test_getAccessKeyPairSuccess(t *testing.T) {
 }
 
 func Test_getAccessKeyPairFailed(t *testing.T) {
-       defer func() {
-               e := recover()
-               assert.NotNil(t, e)
-       }()
        testUrl := common.NewURLWithOptions(
                common.WithParams(url.Values{}),
                common.WithParamsValue(constant.AccessKeyIDKey, "akey"))
@@ -119,9 +115,11 @@ func Test_getAccessKeyPairFailed(t *testing.T) {
        testUrl = common.NewURLWithOptions(
                common.WithParams(url.Values{}),
                common.WithParamsValue(constant.SecretAccessKeyKey, "skey"),
-               common.WithParamsValue(constant.AccessKeyIDKey, "akey"), 
common.WithParamsValue(constant.AccessKeyStorageKey, "dubbo"))
+               common.WithParamsValue(constant.AccessKeyIDKey, "akey"),
+               common.WithParamsValue(constant.AccessKeyStorageKey, "dubbo"))
        _, e = getAccessKeyPair(rpcInvocation, testUrl)
-       assert.NoError(t, e)
+       assert.NotNil(t, e)
+       assert.Contains(t, e.Error(), "accessKeyStorages for dubbo is not 
existing")
 }
 
 func Test_getSignatureWithinParams(t *testing.T) {

Reply via email to