Skip to content

Commit e7bbf1c

Browse files
committed
[FAB-3055] Enhance the url check on chaincode path
Now we can detect invalid path like '/' or 'http:///'. Also add new test case. Fix https://jira.hyperledger.org/browse/FAB-3055. Change-Id: I28cca3b11ead61563220cc4eda6cb01a0feb8004 Signed-off-by: Baohua Yang <[email protected]>
1 parent 0640d43 commit e7bbf1c

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

core/chaincode/platforms/golang/platform.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func decodeUrl(spec *pb.ChaincodeSpec) (string, error) {
6060
urlLocation = spec.ChaincodeId.Path
6161
}
6262

63-
if urlLocation == "" {
64-
return "", errors.New("ChaincodeSpec's path/URL cannot be empty")
63+
if len(urlLocation) < 2 {
64+
return "", errors.New("ChaincodeSpec's path/URL invalid")
6565
}
6666

6767
if strings.LastIndex(urlLocation, "/") == len(urlLocation)-1 {

core/chaincode/platforms/golang/platform_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,38 @@ func Test_writeGopathSrc(t *testing.T) {
8888
//ioutil.WriteFile("/tmp/chaincode_deployment.tar", inputbuf.Bytes(), 0644)
8989

9090
}
91+
92+
func Test_decodeUrl(t *testing.T) {
93+
cs := &pb.ChaincodeSpec{
94+
ChaincodeId: &pb.ChaincodeID{
95+
Name: "Test Chaincode",
96+
Path: "http://github.com/hyperledger/fabric/examples/chaincode/go/map",
97+
},
98+
}
99+
100+
if _, err := decodeUrl(cs); err != nil {
101+
t.Fail()
102+
t.Logf("Error to decodeUrl unsuccessfully with valid path: %s, %s", cs.ChaincodeId.Path, err)
103+
}
104+
105+
cs.ChaincodeId.Path = ""
106+
107+
if _, err := decodeUrl(cs); err == nil {
108+
t.Fail()
109+
t.Logf("Error to decodeUrl successfully with invalid path: %s", cs.ChaincodeId.Path)
110+
}
111+
112+
cs.ChaincodeId.Path = "/"
113+
114+
if _, err := decodeUrl(cs); err == nil {
115+
t.Fail()
116+
t.Logf("Error to decodeUrl successfully with invalid path: %s", cs.ChaincodeId.Path)
117+
}
118+
119+
cs.ChaincodeId.Path = "http:///"
120+
121+
if _, err := decodeUrl(cs); err == nil {
122+
t.Fail()
123+
t.Logf("Error to decodeUrl successfully with invalid path: %s", cs.ChaincodeId.Path)
124+
}
125+
}

0 commit comments

Comments
 (0)