-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathblobber_objecttree_test.go
182 lines (136 loc) · 8.03 KB
/
blobber_objecttree_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package api_tests
import (
"testing"
"time"
"github.com/0chain/system_test/internal/api/util/test"
"github.com/0chain/gosdk/core/encryption"
"github.com/0chain/system_test/internal/api/model"
"github.com/0chain/system_test/internal/api/util/client"
"github.com/0chain/system_test/internal/api/util/crypto"
"github.com/stretchr/testify/require"
)
func TestObjectTree(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
t.SetSmokeTests("Get object tree with allocation id, remote path should work")
t.RunSequentially("Get object tree with allocation id, remote path should work", func(t *test.SystemTest) {
wallet := createWallet(t)
sdkClient.SetWallet(t, wallet)
blobberRequirements := model.DefaultBlobberRequirements(wallet.Id, wallet.PublicKey)
allocationBlobbers := apiClient.GetAllocationBlobbers(t, wallet, &blobberRequirements, client.HttpOkStatus)
allocationID := apiClient.CreateAllocation(t, wallet, allocationBlobbers, client.TxSuccessfulStatus)
allocation := apiClient.GetAllocation(t, allocationID, client.HttpOkStatus)
remoteFilePath, _ := sdkClient.UploadFile(t, allocationID)
remoteFilePath = "/" + remoteFilePath
blobberID := getFirstUsedStorageNodeID(allocationBlobbers.Blobbers, allocation.Blobbers)
require.NotZero(t, blobberID)
blobber := apiClient.GetBlobber(t, blobberID, client.HttpOkStatus)
url := blobber.BaseURL
keyPair := crypto.GenerateKeys(t, wallet.Mnemonics)
sign := encryption.Hash(allocation.Tx)
clientSignature := crypto.SignHexString(t, sign, &keyPair.PrivateKey)
blobberObjectTreeRequest := newBlobberObjectTreeRequest(url, wallet, allocationID, clientSignature, remoteFilePath)
blobberObjectTreeResponse, resp, err := apiClient.V1BlobberObjectTree(t, blobberObjectTreeRequest, client.HttpOkStatus)
require.Nil(t, err)
require.NotNil(t, blobberObjectTreeResponse)
require.Equal(t, resp.StatusCode(), client.HttpOkStatus, resp)
require.Equal(t, blobberObjectTreeResponse.Meta["path"].(string), remoteFilePath)
require.Equal(t, blobberObjectTreeResponse.Meta["type"].(string), "f")
// TODO add more assertions once there blobber endpoints are documented
})
t.RunSequentially("Get file ref for empty allocation should work", func(t *test.SystemTest) {
wallet := createWallet(t)
blobberRequirements := model.DefaultBlobberRequirements(wallet.Id, wallet.PublicKey)
allocationBlobbers := apiClient.GetAllocationBlobbers(t, wallet, &blobberRequirements, client.HttpOkStatus)
allocationID := apiClient.CreateAllocation(t, wallet, allocationBlobbers, client.TxSuccessfulStatus)
allocation := apiClient.GetAllocation(t, allocationID, client.HttpOkStatus)
remoteFilePath := "/"
blobberID := getFirstUsedStorageNodeID(allocationBlobbers.Blobbers, allocation.Blobbers)
require.NotZero(t, blobberID)
blobber := apiClient.GetBlobber(t, blobberID, client.HttpOkStatus)
url := blobber.BaseURL
keyPair := crypto.GenerateKeys(t, wallet.Mnemonics)
sign := encryption.Hash(allocation.Tx)
clientSignature := crypto.SignHexString(t, sign, &keyPair.PrivateKey)
blobberObjectTreeRequest := newBlobberObjectTreeRequest(url, wallet, allocationID, clientSignature, remoteFilePath)
blobberObjectTreeResponse, resp, err := apiClient.V1BlobberObjectTree(t, blobberObjectTreeRequest, client.HttpOkStatus)
require.Nil(t, err)
require.NotNil(t, blobberObjectTreeResponse)
require.Equal(t, resp.StatusCode(), client.HttpOkStatus, resp)
require.NotNil(t, blobberObjectTreeResponse.Meta)
// TODO add more assertions once there blobber endpoints are documented
})
t.RunSequentiallyWithTimeout("Get file ref with invalid allocation id should fail", 90*time.Second, func(t *test.SystemTest) { //TODO: Why is this so slow? (69s)
wallet := createWallet(t)
sdkClient.SetWallet(t, wallet)
blobberRequirements := model.DefaultBlobberRequirements(wallet.Id, wallet.PublicKey)
allocationBlobbers := apiClient.GetAllocationBlobbers(t, wallet, &blobberRequirements, client.HttpOkStatus)
allocationID := apiClient.CreateAllocation(t, wallet, allocationBlobbers, client.TxSuccessfulStatus)
allocation := apiClient.GetAllocation(t, allocationID, client.HttpOkStatus)
remoteFilePath, _ := sdkClient.UploadFile(t, allocationID)
remoteFilePath = "/" + remoteFilePath
blobberID := getFirstUsedStorageNodeID(allocationBlobbers.Blobbers, allocation.Blobbers)
require.NotZero(t, blobberID)
blobber := apiClient.GetBlobber(t, blobberID, client.HttpOkStatus)
blobberUrl := blobber.BaseURL
keyPair := crypto.GenerateKeys(t, wallet.Mnemonics)
sign := encryption.Hash(allocation.Tx)
clientSignature := crypto.SignHexString(t, sign, &keyPair.PrivateKey)
blobberObjectTreeRequest := newBlobberObjectTreeRequest(blobberUrl, wallet, "invalid_allocation_id", clientSignature, remoteFilePath)
blobberObjectTreeResponse, resp, err := apiClient.V1BlobberObjectTree(t, blobberObjectTreeRequest, client.HttpOkStatus)
// FIXME: error should be returned
require.Nil(t, err)
require.Empty(t, blobberObjectTreeResponse)
require.Equal(t, resp.StatusCode(), client.HttpBadRequestStatus)
})
t.RunSequentially("Get file ref with invalid sign should fail", func(t *test.SystemTest) {
wallet := createWallet(t)
sdkClient.SetWallet(t, wallet)
blobberRequirements := model.DefaultBlobberRequirements(wallet.Id, wallet.PublicKey)
allocationBlobbers := apiClient.GetAllocationBlobbers(t, wallet, &blobberRequirements, client.HttpOkStatus)
allocationID := apiClient.CreateAllocation(t, wallet, allocationBlobbers, client.TxSuccessfulStatus)
allocation := apiClient.GetAllocation(t, allocationID, client.HttpOkStatus)
remoteFilePath, _ := sdkClient.UploadFile(t, allocationID)
remoteFilePath = "/" + remoteFilePath
blobberID := getFirstUsedStorageNodeID(allocationBlobbers.Blobbers, allocation.Blobbers)
require.NotZero(t, blobberID)
blobber := apiClient.GetBlobber(t, blobberID, client.HttpOkStatus)
blobberUrl := blobber.BaseURL
blobberObjectTreeRequest := newBlobberObjectTreeRequest(blobberUrl, wallet, allocation.ID, "invalid_signature", remoteFilePath)
blobberObjectTreeResponse, resp, err := apiClient.V1BlobberObjectTree(t, blobberObjectTreeRequest, client.HttpOkStatus)
// FIXME: error should be returned
require.Nil(t, err)
require.Empty(t, blobberObjectTreeResponse)
require.Equal(t, resp.StatusCode(), client.HttpBadRequestStatus)
})
t.RunSequentially("Get file ref with invalid remotepath should fail", func(t *test.SystemTest) {
wallet := createWallet(t)
blobberRequirements := model.DefaultBlobberRequirements(wallet.Id, wallet.PublicKey)
allocationBlobbers := apiClient.GetAllocationBlobbers(t, wallet, &blobberRequirements, client.HttpOkStatus)
allocationID := apiClient.CreateAllocation(t, wallet, allocationBlobbers, client.TxSuccessfulStatus)
allocation := apiClient.GetAllocation(t, allocationID, client.HttpOkStatus)
blobberID := getFirstUsedStorageNodeID(allocationBlobbers.Blobbers, allocation.Blobbers)
require.NotZero(t, blobberID)
blobber := apiClient.GetBlobber(t, blobberID, client.HttpOkStatus)
blobberUrl := blobber.BaseURL
keyPair := crypto.GenerateKeys(t, wallet.Mnemonics)
sign := encryption.Hash(allocation.Tx)
clientSignature := crypto.SignHexString(t, sign, &keyPair.PrivateKey)
blobberObjectTreeRequest := newBlobberObjectTreeRequest(blobberUrl, wallet, allocation.ID, clientSignature, "invalid_path")
blobberObjectTreeResponse, resp, err := apiClient.V1BlobberObjectTree(t, blobberObjectTreeRequest, client.HttpOkStatus)
// FIXME: error should be returned
require.Nil(t, err)
require.Empty(t, blobberObjectTreeResponse)
require.Equal(t, resp.StatusCode(), client.HttpNotFoundStatus)
})
}
func newBlobberObjectTreeRequest(url string, registeredwallet *model.Wallet, allocationId, clientSignature, remotePath string) *model.BlobberObjectTreeRequest {
blobberObjectTreeRequest := model.BlobberObjectTreeRequest{
URL: url,
ClientID: registeredwallet.Id,
ClientKey: registeredwallet.PublicKey,
ClientSignature: clientSignature,
AllocationID: allocationId,
Path: remotePath,
}
return &blobberObjectTreeRequest
}