2016-11-07 14:43:35 -05:00
|
|
|
/*
|
2017-03-18 14:28:41 -04:00
|
|
|
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
|
2016-11-07 14:43:35 -05:00
|
|
|
*
|
|
|
|
* 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 (
|
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// API suite container common to both FS and XL.
|
|
|
|
type TestRPCBrowserPeerSuite struct {
|
|
|
|
serverType string
|
|
|
|
testServer TestServer
|
2016-12-23 10:12:19 -05:00
|
|
|
testAuthConf authConfig
|
2016-11-07 14:43:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setting up the test suite and starting the Test server.
|
|
|
|
func (s *TestRPCBrowserPeerSuite) SetUpSuite(c *testing.T) {
|
|
|
|
s.testServer = StartTestBrowserPeerRPCServer(c, s.serverType)
|
2016-12-23 10:12:19 -05:00
|
|
|
s.testAuthConf = authConfig{
|
|
|
|
serverAddr: s.testServer.Server.Listener.Addr().String(),
|
|
|
|
accessKey: s.testServer.AccessKey,
|
|
|
|
secretKey: s.testServer.SecretKey,
|
2017-02-16 17:52:14 -05:00
|
|
|
serviceEndpoint: path.Join(minioReservedBucketPath, browserPeerPath),
|
2016-12-23 10:12:19 -05:00
|
|
|
serviceName: "BrowserPeer",
|
2016-11-07 14:43:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No longer used with gocheck, but used in explicit teardown code in
|
|
|
|
// each test function. // Called implicitly by "gopkg.in/check.v1"
|
|
|
|
// after all tests are run.
|
|
|
|
func (s *TestRPCBrowserPeerSuite) TearDownSuite(c *testing.T) {
|
|
|
|
s.testServer.Stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBrowserPeerRPC(t *testing.T) {
|
|
|
|
// setup code
|
|
|
|
s := &TestRPCBrowserPeerSuite{serverType: "XL"}
|
|
|
|
s.SetUpSuite(t)
|
|
|
|
|
|
|
|
// run test
|
|
|
|
s.testBrowserPeerRPC(t)
|
|
|
|
|
|
|
|
// teardown code
|
|
|
|
s.TearDownSuite(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for browser peer rpc.
|
|
|
|
func (s *TestRPCBrowserPeerSuite) testBrowserPeerRPC(t *testing.T) {
|
|
|
|
// Construct RPC call arguments.
|
2017-03-16 03:16:06 -04:00
|
|
|
creds, err := createCredential("abcd1", "abcd1234")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to create credential. %v", err)
|
2016-11-07 14:43:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate for invalid token.
|
|
|
|
args := SetAuthPeerArgs{Creds: creds}
|
2016-12-23 10:12:19 -05:00
|
|
|
args.AuthToken = "garbage"
|
|
|
|
rclient := newRPCClient(s.testAuthConf.serverAddr, s.testAuthConf.serviceEndpoint, false)
|
2016-11-07 14:43:35 -05:00
|
|
|
defer rclient.Close()
|
2017-03-16 03:16:06 -04:00
|
|
|
err = rclient.Call("BrowserPeer.SetAuthPeer", &args, &AuthRPCReply{})
|
2016-11-07 14:43:35 -05:00
|
|
|
if err != nil {
|
|
|
|
if err.Error() != errInvalidToken.Error() {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate for successful Peer update.
|
|
|
|
args = SetAuthPeerArgs{Creds: creds}
|
2016-12-23 10:12:19 -05:00
|
|
|
client := newAuthRPCClient(s.testAuthConf)
|
2016-11-07 14:43:35 -05:00
|
|
|
defer client.Close()
|
2016-12-23 10:12:19 -05:00
|
|
|
err = client.Call("BrowserPeer.SetAuthPeer", &args, &AuthRPCReply{})
|
2016-11-07 14:43:35 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate for failure in login handler with previous credentials.
|
2016-12-23 10:12:19 -05:00
|
|
|
rclient = newRPCClient(s.testAuthConf.serverAddr, s.testAuthConf.serviceEndpoint, false)
|
2016-11-07 14:43:35 -05:00
|
|
|
defer rclient.Close()
|
2017-09-19 15:37:56 -04:00
|
|
|
token, err := authenticateNode(creds.AccessKey, creds.SecretKey)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-12-23 10:12:19 -05:00
|
|
|
rargs := &LoginRPCArgs{
|
2017-09-19 15:37:56 -04:00
|
|
|
AuthToken: token,
|
2016-12-23 10:12:19 -05:00
|
|
|
Version: Version,
|
2017-03-18 14:28:41 -04:00
|
|
|
RequestTime: UTCNow(),
|
2016-11-07 14:43:35 -05:00
|
|
|
}
|
2016-12-23 10:12:19 -05:00
|
|
|
rreply := &LoginRPCReply{}
|
|
|
|
err = rclient.Call("BrowserPeer"+loginMethodName, rargs, rreply)
|
2016-11-07 14:43:35 -05:00
|
|
|
if err != nil {
|
|
|
|
if err.Error() != errInvalidAccessKeyID.Error() {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-19 15:37:56 -04:00
|
|
|
token, err = authenticateNode(creds.AccessKey, creds.SecretKey)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-07 14:43:35 -05:00
|
|
|
// Validate for success in loing handled with valid credetnails.
|
2016-12-23 10:12:19 -05:00
|
|
|
rargs = &LoginRPCArgs{
|
2017-09-19 15:37:56 -04:00
|
|
|
AuthToken: token,
|
2016-12-23 10:12:19 -05:00
|
|
|
Version: Version,
|
2017-03-18 14:28:41 -04:00
|
|
|
RequestTime: UTCNow(),
|
2016-11-07 14:43:35 -05:00
|
|
|
}
|
2016-12-23 10:12:19 -05:00
|
|
|
rreply = &LoginRPCReply{}
|
2017-09-19 15:37:56 -04:00
|
|
|
if err = rclient.Call("BrowserPeer"+loginMethodName, rargs, rreply); err != nil {
|
2016-11-07 14:43:35 -05:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|