2016-11-11 01:43:04 +01:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2014-2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2017-08-13 04:25:43 +02:00
|
|
|
"os"
|
2016-11-11 01:43:04 +01:00
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TestRPCS3PeerSuite struct {
|
|
|
|
testServer TestServer
|
2016-12-23 16:12:19 +01:00
|
|
|
testAuthConf authConfig
|
2016-11-11 01:43:04 +01:00
|
|
|
disks []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the suite and start the test server.
|
|
|
|
func (s *TestRPCS3PeerSuite) SetUpSuite(t *testing.T) {
|
|
|
|
s.testServer, s.disks = StartTestS3PeerRPCServer(t)
|
2016-12-23 16:12:19 +01:00
|
|
|
s.testAuthConf = authConfig{
|
|
|
|
serverAddr: s.testServer.Server.Listener.Addr().String(),
|
|
|
|
accessKey: s.testServer.AccessKey,
|
|
|
|
secretKey: s.testServer.SecretKey,
|
2017-02-16 23:52:14 +01:00
|
|
|
serviceEndpoint: path.Join(minioReservedBucketPath, s3Path),
|
2016-12-23 16:12:19 +01:00
|
|
|
serviceName: "S3",
|
2016-11-11 01:43:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TestRPCS3PeerSuite) TearDownSuite(t *testing.T) {
|
|
|
|
s.testServer.Stop()
|
|
|
|
removeRoots(s.disks)
|
2017-08-13 04:25:43 +02:00
|
|
|
os.RemoveAll(s.testServer.Root)
|
2016-11-11 01:43:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestS3PeerRPC(t *testing.T) {
|
|
|
|
// setup
|
|
|
|
s := &TestRPCS3PeerSuite{}
|
|
|
|
s.SetUpSuite(t)
|
|
|
|
|
|
|
|
// run test
|
|
|
|
s.testS3PeerRPC(t)
|
|
|
|
|
|
|
|
// teardown
|
|
|
|
s.TearDownSuite(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test S3 RPC handlers
|
|
|
|
func (s *TestRPCS3PeerSuite) testS3PeerRPC(t *testing.T) {
|
|
|
|
// Validate for invalid token.
|
2018-01-20 01:38:47 +01:00
|
|
|
args := AuthRPCArgs{}
|
|
|
|
rclient := newAuthRPCClient(s.testAuthConf)
|
2016-11-11 01:43:04 +01:00
|
|
|
defer rclient.Close()
|
2018-01-20 01:38:47 +01:00
|
|
|
|
|
|
|
if err := rclient.Login(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rclient.authToken = "garbage"
|
2016-12-23 16:12:19 +01:00
|
|
|
err := rclient.Call("S3.SetBucketNotificationPeer", &args, &AuthRPCReply{})
|
2016-11-11 01:43:04 +01:00
|
|
|
if err != nil {
|
|
|
|
if err.Error() != errInvalidToken.Error() {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check bucket notification call works.
|
2016-11-21 22:51:05 +01:00
|
|
|
BNPArgs := SetBucketNotificationPeerArgs{Bucket: "bucket", NCfg: ¬ificationConfig{}}
|
2016-12-23 16:12:19 +01:00
|
|
|
client := newAuthRPCClient(s.testAuthConf)
|
2016-11-11 01:43:04 +01:00
|
|
|
defer client.Close()
|
2016-12-23 16:12:19 +01:00
|
|
|
err = client.Call("S3.SetBucketNotificationPeer", &BNPArgs, &AuthRPCReply{})
|
2016-11-11 01:43:04 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check bucket listener update call works.
|
2016-11-21 22:51:05 +01:00
|
|
|
BLPArgs := SetBucketListenerPeerArgs{Bucket: "bucket", LCfg: nil}
|
2016-12-23 16:12:19 +01:00
|
|
|
err = client.Call("S3.SetBucketListenerPeer", &BLPArgs, &AuthRPCReply{})
|
2016-11-11 01:43:04 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check bucket policy update call works.
|
|
|
|
pCh := policyChange{IsRemove: true}
|
|
|
|
pChBytes, err := json.Marshal(pCh)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-21 22:51:05 +01:00
|
|
|
BPPArgs := SetBucketPolicyPeerArgs{Bucket: "bucket", PChBytes: pChBytes}
|
2016-12-23 16:12:19 +01:00
|
|
|
err = client.Call("S3.SetBucketPolicyPeer", &BPPArgs, &AuthRPCReply{})
|
2016-11-11 01:43:04 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check event send event call works.
|
|
|
|
evArgs := EventArgs{Event: nil, Arn: "localhost:9000"}
|
2016-12-23 16:12:19 +01:00
|
|
|
err = client.Call("S3.Event", &evArgs, &AuthRPCReply{})
|
2016-11-11 01:43:04 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|