code.gitea.io/gitea@v1.21.7/routers/web/admin/admin_test.go (about)

     1  // Copyright 2019 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package admin
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestShadowPassword(t *testing.T) {
    13  	kases := []struct {
    14  		Provider string
    15  		CfgItem  string
    16  		Result   string
    17  	}{
    18  		{
    19  			Provider: "redis",
    20  			CfgItem:  "network=tcp,addr=:6379,password=gitea,db=0,pool_size=100,idle_timeout=180",
    21  			Result:   "network=tcp,addr=:6379,password=******,db=0,pool_size=100,idle_timeout=180",
    22  		},
    23  		{
    24  			Provider: "mysql",
    25  			CfgItem:  "root:@tcp(localhost:3306)/gitea?charset=utf8",
    26  			Result:   "root:******@tcp(localhost:3306)/gitea?charset=utf8",
    27  		},
    28  		{
    29  			Provider: "mysql",
    30  			CfgItem:  "/gitea?charset=utf8",
    31  			Result:   "/gitea?charset=utf8",
    32  		},
    33  		{
    34  			Provider: "mysql",
    35  			CfgItem:  "user:mypassword@/dbname",
    36  			Result:   "user:******@/dbname",
    37  		},
    38  		{
    39  			Provider: "postgres",
    40  			CfgItem:  "user=pqgotest dbname=pqgotest sslmode=verify-full",
    41  			Result:   "user=pqgotest dbname=pqgotest sslmode=verify-full",
    42  		},
    43  		{
    44  			Provider: "postgres",
    45  			CfgItem:  "user=pqgotest password= dbname=pqgotest sslmode=verify-full",
    46  			Result:   "user=pqgotest password=****** dbname=pqgotest sslmode=verify-full",
    47  		},
    48  		{
    49  			Provider: "postgres",
    50  			CfgItem:  "postgres://user:pass@hostname/dbname",
    51  			Result:   "postgres://user:******@hostname/dbname",
    52  		},
    53  		{
    54  			Provider: "couchbase",
    55  			CfgItem:  "http://dev-couchbase.example.com:8091/",
    56  			Result:   "http://dev-couchbase.example.com:8091/",
    57  		},
    58  		{
    59  			Provider: "couchbase",
    60  			CfgItem:  "http://user:the_password@dev-couchbase.example.com:8091/",
    61  			Result:   "http://user:******@dev-couchbase.example.com:8091/",
    62  		},
    63  	}
    64  
    65  	for _, k := range kases {
    66  		assert.EqualValues(t, k.Result, shadowPassword(k.Provider, k.CfgItem))
    67  	}
    68  }