Exemple #1
0
func (s *LocalServer) SetUp(c *gocheck.C) {
	srv, err := elbtest.NewServer()
	c.Assert(err, gocheck.IsNil)
	c.Assert(srv, gocheck.NotNil)
	s.srv = srv
	s.region = aws.Region{ELBEndpoint: srv.URL()}
}
func (s *S) TestDescribeScheduledActions(c *gocheck.C) {
	testServer.Response(200, nil, DescribeScheduledActionsResponse)
	st, _ := time.Parse(time.RFC3339, "2014-06-01T00:30:00Z")
	request := &DescribeScheduledActionsParams{
		AutoScalingGroupName: "ASGTest1",
		MaxRecords:           1,
		StartTime:            st,
	}
	resp, err := s.as.DescribeScheduledActions(request)
	c.Assert(err, gocheck.IsNil)
	values := testServer.WaitRequest().PostForm
	c.Assert(values.Get("Version"), gocheck.Equals, "2011-01-01")
	c.Assert(values.Get("Action"), gocheck.Equals, "DescribeScheduledActions")
	c.Assert(resp.RequestId, gocheck.Equals, "0eb4217f-8421-11e3-9233-7100ef811766")
	c.Assert(resp.ScheduledUpdateGroupActions, gocheck.DeepEquals, []ScheduledUpdateGroupAction{
		{
			AutoScalingGroupName: "ASGTest1",
			ScheduledActionARN:   "arn:aws:autoscaling:us-west-2:193024542802:scheduledUpdateGroupAction:61f68b2c-bde3-4316-9a81-eb95dc246509:autoScalingGroupName/ASGTest1:scheduledActionName/SATest1",
			ScheduledActionName:  "SATest1",
			Recurrence:           "30 0 1 1,6,12 *",
			MaxSize:              4,
			StartTime:            st,
			Time:                 st,
		},
	})
}
func (s *S) TestExitStandby(c *gocheck.C) {
	testServer.Response(200, nil, ExitStandbyResponse)
	resp, err := s.as.ExitStandby("my-asg", []string{"i-5b73d709"})
	c.Assert(err, gocheck.IsNil)
	values := testServer.WaitRequest().PostForm
	c.Assert(values.Get("Version"), gocheck.Equals, "2011-01-01")
	c.Assert(values.Get("Action"), gocheck.Equals, "ExitStandby")
	c.Assert(values.Get("AutoScalingGroupName"), gocheck.Equals, "my-asg")
	c.Assert(values.Get("InstanceIds.member.1"), gocheck.Equals, "i-5b73d709")
	st, _ := time.Parse(time.RFC3339, "2014-06-13T22:43:53.523Z")
	expected := &ExitStandbyResult{
		RequestId: "321a11c8-f34c-11e3-a434-7f10009d5849",
		Activities: []Activity{
			{
				StatusCode:           "PreInService",
				Progress:             30,
				ActivityId:           "dca4efcf-eea6-4844-8064-cab1fecd1aa2",
				StartTime:            st,
				AutoScalingGroupName: "my-asg",
				Details:              "{\"Availability Zone\":\"us-east-1a\"}",
				Cause:                "At 2014-06-13T22:43:53Z instance i-5b73d709 was moved out of standby in response to a user request, increasing the capacity from 3 to 4.",
				Description:          "Moving EC2 instance out of Standby: i-5b73d709",
			},
		},
	}
	c.Assert(resp, gocheck.DeepEquals, expected)
}
Exemple #4
0
func (s *S) TestListGroups(c *gocheck.C) {
	testServer.Response(200, nil, ListGroupsExample)
	resp, err := s.iam.Groups("/division_abc/")
	values := testServer.WaitRequest().URL.Query()
	c.Assert(values.Get("Action"), gocheck.Equals, "ListGroups")
	c.Assert(values.Get("PathPrefix"), gocheck.Equals, "/division_abc/")
	c.Assert(err, gocheck.IsNil)
	c.Assert(resp.RequestId, gocheck.Equals, "7a62c49f-347e-4fc4-9331-6e8eEXAMPLE")
	expected := []iam.Group{
		{
			Path: "/division_abc/subdivision_xyz/",
			Name: "Admins",
			Id:   "AGPACKCEVSQ6C2EXAMPLE",
			Arn:  "arn:aws:iam::123456789012:group/Admins",
		},
		{
			Path: "/division_abc/subdivision_xyz/product_1234/engineering/",
			Name: "Test",
			Id:   "AGP2MAB8DPLSRHEXAMPLE",
			Arn:  "arn:aws:iam::123456789012:group/division_abc/subdivision_xyz/product_1234/engineering/Test",
		},
		{
			Path: "/division_abc/subdivision_xyz/product_1234/",
			Name: "Managers",
			Id:   "AGPIODR4TAW7CSEXAMPLE",
			Arn:  "arn:aws:iam::123456789012:group/division_abc/subdivision_xyz/product_1234/Managers",
		},
	}
	c.Assert(resp.Groups, gocheck.DeepEquals, expected)
}
Exemple #5
0
func (s *S) SetUpSuite(c *gocheck.C) {
	var err error
	testServer.Start()
	auth := aws.Auth{AccessKey: "abc", SecretKey: "123"}
	s.rds, err = rds.New(auth, aws.Region{RDSEndpoint: aws.ServiceInfo{testServer.URL, aws.V2Signature}})
	c.Assert(err, gocheck.IsNil)
}
func (s *V4SignerSuite) TestCases(c *gocheck.C) {
	signer := aws.NewV4Signer(s.auth, "host", s.region)

	for _, testCase := range s.cases {

		req, err := http.NewRequest(testCase.request.method, "http://"+testCase.request.host+testCase.request.url, strings.NewReader(testCase.request.body))
		c.Assert(err, gocheck.IsNil, gocheck.Commentf("Testcase: %s", testCase.label))
		for _, v := range testCase.request.headers {
			h := strings.SplitN(v, ":", 2)
			req.Header.Add(h[0], h[1])
		}
		req.Header.Set("host", req.Host)

		t := signer.RequestTime(req)

		canonicalRequest := signer.CanonicalRequest(req)
		c.Check(canonicalRequest, gocheck.Equals, testCase.canonicalRequest, gocheck.Commentf("Testcase: %s", testCase.label))

		stringToSign := signer.StringToSign(t, canonicalRequest)
		c.Check(stringToSign, gocheck.Equals, testCase.stringToSign, gocheck.Commentf("Testcase: %s", testCase.label))

		signature := signer.Signature(t, stringToSign)
		c.Check(signature, gocheck.Equals, testCase.signature, gocheck.Commentf("Testcase: %s", testCase.label))

		authorization := signer.Authorization(req.Header, t, signature)
		c.Check(authorization, gocheck.Equals, testCase.authorization, gocheck.Commentf("Testcase: %s", testCase.label))

		signer.Sign(req)
		c.Check(req.Header.Get("Authorization"), gocheck.Equals, testCase.authorization, gocheck.Commentf("Testcase: %s", testCase.label))
	}
}
Exemple #7
0
func (s *S) TestEscaping(c *gocheck.C) {
	params := map[string]string{"Nonce": "+ +"}
	elb.Sign(testAuth, "GET", "/path", params, "localhost")
	c.Assert(params["Nonce"], gocheck.Equals, "+ +")
	expected := "bqffDELReIqwjg/W0DnsnVUmfLK4wXVLO4/LuG+1VFA="
	c.Assert(params["Signature"], gocheck.Equals, expected)
}
Exemple #8
0
func (s *ClientTests) createInstanceAndLB(c *gocheck.C) (*elb.CreateLoadBalancer, string) {
	options := ec2.RunInstancesOptions{
		ImageId:          "ami-ccf405a5",
		InstanceType:     "t1.micro",
		AvailabilityZone: "us-east-1c",
	}
	resp1, err := s.ec2.RunInstances(&options)
	c.Assert(err, gocheck.IsNil)
	instId := resp1.Instances[0].InstanceId
	createLBReq := elb.CreateLoadBalancer{
		Name:              "testlb",
		AvailabilityZones: []string{"us-east-1c"},
		Listeners: []elb.Listener{
			{
				InstancePort:     80,
				InstanceProtocol: "http",
				LoadBalancerPort: 80,
				Protocol:         "http",
			},
		},
	}
	_, err = s.elb.CreateLoadBalancer(&createLBReq)
	c.Assert(err, gocheck.IsNil)
	return &createLBReq, instId
}
Exemple #9
0
func (s *S) TestDescribeInstanceHealthBadRequest(c *gocheck.C) {
	testServer.PrepareResponse(400, nil, DescribeInstanceHealthBadRequest)
	resp, err := s.elb.DescribeInstanceHealth("testlb", "i-foooo")
	c.Assert(err, gocheck.NotNil)
	c.Assert(resp, gocheck.IsNil)
	c.Assert(err, gocheck.ErrorMatches, ".*i-foooo.*(InvalidInstance).*")
}
Exemple #10
0
func (s *S) TestDescribeLoadBalancersBadRequest(c *gocheck.C) {
	testServer.PrepareResponse(400, nil, DescribeLoadBalancersBadRequest)
	resp, err := s.elb.DescribeLoadBalancers()
	c.Assert(resp, gocheck.IsNil)
	c.Assert(err, gocheck.NotNil)
	c.Assert(err, gocheck.ErrorMatches, `^Cannot find Load Balancer absentlb \(LoadBalancerNotFound\)$`)
}
func (s *S) TestGetTemplate(c *gocheck.C) {
	testServer.Response(200, nil, GetTemplateResponse)

	resp, err := s.cf.GetTemplate("MyStack")
	c.Assert(err, gocheck.IsNil)
	values := testServer.WaitRequest().PostForm
	// Post request test
	c.Assert(values.Get("Version"), gocheck.Equals, "2010-05-15")
	c.Assert(values.Get("Action"), gocheck.Equals, "GetTemplate")

	c.Assert(values.Get("StackName"), gocheck.Equals, "MyStack")
	// Response test
	templateBody := `{
      "AWSTemplateFormatVersion" : "2010-09-09",
      "Description" : "Simple example",
      "Resources" : {
        "MySQS" : {
           "Type" : "AWS::SQS::Queue",
           "Properties" : {
            }
         }
        }
      }`
	c.Assert(resp.TemplateBody, gocheck.Equals, templateBody)
	c.Assert(resp.RequestId, gocheck.Equals, "4af14eec-350e-11e4-b260-EXAMPLE")
}
Exemple #12
0
func (s *S) TestEnvAuthAlt(c *gocheck.C) {
	os.Clearenv()
	os.Setenv("AWS_SECRET_KEY", "secret")
	os.Setenv("AWS_ACCESS_KEY", "access")
	auth, err := aws.EnvAuth()
	c.Assert(err, gocheck.IsNil)
	c.Assert(auth, gocheck.Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
}
Exemple #13
0
func (s *S) TestGetAuthEnv(c *gocheck.C) {
	os.Clearenv()
	os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
	os.Setenv("AWS_ACCESS_KEY_ID", "access")
	auth, err := aws.GetAuth("", "", "", time.Time{})
	c.Assert(err, gocheck.IsNil)
	c.Assert(auth, gocheck.Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
}
Exemple #14
0
func (s *ClientTests) TestListAccessKeysUserNotFound(c *gocheck.C) {
	_, err := s.iam.AccessKeys("unknowngopher")
	c.Assert(err, gocheck.NotNil)
	iamErr, ok := err.(*iam.Error)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(iamErr.StatusCode, gocheck.Equals, 404)
	c.Assert(iamErr.Code, gocheck.Equals, "NoSuchEntity")
	c.Assert(iamErr.Message, gocheck.Equals, "The user with name unknowngopher cannot be found.")
}
Exemple #15
0
func checkContents(c *gocheck.C, contents []s3.Key, data map[string][]byte, expected []s3.Key) {
	c.Assert(contents, gocheck.HasLen, len(expected))
	for i, k := range contents {
		c.Check(k.Key, gocheck.Equals, expected[i].Key)
		// TODO mtime
		c.Check(k.Size, gocheck.Equals, int64(len(data[k.Key])))
		c.Check(k.ETag, gocheck.Equals, etag(data[k.Key]))
	}
}
Exemple #16
0
func (s *LocalServerSuite) TestDeregisterInstancewithLoadBalancerWithAbsentInstance(c *gocheck.C) {
	srv := s.srv.srv
	srv.NewLoadBalancer("testlb")
	defer srv.RemoveLoadBalancer("testlb")
	resp, err := s.clientTests.elb.DeregisterInstancesFromLoadBalancer([]string{"i-212"}, "testlb")
	c.Assert(resp, gocheck.IsNil)
	c.Assert(err, gocheck.NotNil)
	c.Assert(err, gocheck.ErrorMatches, `^InvalidInstance found in \[i-212\]. Invalid id: "i-212" \(InvalidInstance\)$`)
}
Exemple #17
0
func (s *LocalServerSuite) TestRegisterInstanceWithLoadBalancer(c *gocheck.C) {
	srv := s.srv.srv
	instId := srv.NewInstance()
	defer srv.RemoveInstance(instId)
	srv.NewLoadBalancer("testlb")
	defer srv.RemoveLoadBalancer("testlb")
	resp, err := s.clientTests.elb.RegisterInstancesWithLoadBalancer([]string{instId}, "testlb")
	c.Assert(err, gocheck.IsNil)
	c.Assert(resp.InstanceIds, gocheck.DeepEquals, []string{instId})
}
Exemple #18
0
func (s *S) TestParamSignature(c *gocheck.C) {
	params := map[string]string{
		"param1": "value1",
		"param2": "value2",
		"param3": "value3",
	}
	elb.Sign(testAuth, "GET", "/path", params, "localhost")
	expected := "XWOR4+0lmK8bD8CGDGZ4kfuSPbb2JibLJiCl/OPu1oU="
	c.Assert(params["Signature"], gocheck.Equals, expected)
}
Exemple #19
0
func (s *S) TestDeleteSecurityGroupExampleWithId(c *gocheck.C) {
	testServer.Response(200, nil, DeleteSecurityGroupExample)

	// ignore return and error - we're only want to check the parameter handling.
	s.ec2.DeleteSecurityGroup(ec2.SecurityGroup{Id: "sg-67ad940e", Name: "ignored"})
	req := testServer.WaitRequest()

	c.Assert(req.Form["GroupName"], gocheck.IsNil)
	c.Assert(req.Form["GroupId"], gocheck.DeepEquals, []string{"sg-67ad940e"})
}
Exemple #20
0
func (s *S) TestSignatureExample1(c *gocheck.C) {
	params := map[string]string{
		"Timestamp": "2009-02-01T12:53:20+00:00",
		"Version":   "2007-11-07",
		"Action":    "ListDomains",
	}
	elb.Sign(aws.Auth{AccessKey: "access", SecretKey: "secret"}, "GET", "/", params, "sdb.amazonaws.com")
	expected := "okj96/5ucWBSc1uR2zXVfm6mDHtgfNv657rRtt/aunQ="
	c.Assert(params["Signature"], gocheck.Equals, expected)
}
Exemple #21
0
func (s *S) TestAddUserToGroup(c *gocheck.C) {
	testServer.Response(200, nil, AddUserToGroupExample)
	resp, err := s.iam.AddUserToGroup("admin1", "Admins")
	values := testServer.WaitRequest().URL.Query()
	c.Assert(values.Get("Action"), gocheck.Equals, "AddUserToGroup")
	c.Assert(values.Get("GroupName"), gocheck.Equals, "Admins")
	c.Assert(values.Get("UserName"), gocheck.Equals, "admin1")
	c.Assert(err, gocheck.IsNil)
	c.Assert(resp.RequestId, gocheck.Equals, "7a62c49f-347e-4fc4-9331-6e8eEXAMPLE")
}
Exemple #22
0
func (s *S) TestDeleteUserPolicy(c *gocheck.C) {
	testServer.Response(200, nil, RequestIdExample)
	resp, err := s.iam.DeleteUserPolicy("Bob", "AllAccessPolicy")
	values := testServer.WaitRequest().URL.Query()
	c.Assert(values.Get("Action"), gocheck.Equals, "DeleteUserPolicy")
	c.Assert(values.Get("PolicyName"), gocheck.Equals, "AllAccessPolicy")
	c.Assert(values.Get("UserName"), gocheck.Equals, "Bob")
	c.Assert(err, gocheck.IsNil)
	c.Assert(resp.RequestId, gocheck.Equals, "7a62c49f-347e-4fc4-9331-6e8eEXAMPLE")
}
Exemple #23
0
func (s *S) TestCreateQueueWithTimeout(c *gocheck.C) {
	testServer.PrepareResponse(200, nil, TestCreateQueueXmlOK)

	s.sqs.CreateQueueWithTimeout("testQueue", 180)
	req := testServer.WaitRequest()

	// TestCreateQueue() tests the core functionality, just check the timeout in this test
	c.Assert(req.Form["Attribute.1.Name"], gocheck.DeepEquals, []string{"VisibilityTimeout"})
	c.Assert(req.Form["Attribute.1.Value"], gocheck.DeepEquals, []string{"180"})
}
Exemple #24
0
func (s *S) TestDeleteAutoScalingGroup(c *gocheck.C) {
	testServer.Response(200, nil, DeleteAutoScalingGroupResponse)
	resp, err := s.as.DeleteAutoScalingGroup("my-test-asg", true)
	c.Assert(err, gocheck.IsNil)
	values := testServer.WaitRequest().PostForm
	c.Assert(values.Get("Version"), gocheck.Equals, "2011-01-01")
	c.Assert(values.Get("Action"), gocheck.Equals, "DeleteAutoScalingGroup")
	c.Assert(values.Get("AutoScalingGroupName"), gocheck.Equals, "my-test-asg")
	c.Assert(resp.RequestId, gocheck.Equals, "70a76d42-9665-11e2-9fdf-211deEXAMPLE")
}
Exemple #25
0
func (s *S) TestDeleteLaunchConfiguration(c *gocheck.C) {
	testServer.Response(200, nil, DeleteLaunchConfigurationResponse)
	resp, err := s.as.DeleteLaunchConfiguration("my-test-lc")
	c.Assert(err, gocheck.IsNil)
	values := testServer.WaitRequest().PostForm
	c.Assert(values.Get("Version"), gocheck.Equals, "2011-01-01")
	c.Assert(values.Get("Action"), gocheck.Equals, "DeleteLaunchConfiguration")
	c.Assert(values.Get("LaunchConfigurationName"), gocheck.Equals, "my-test-lc")
	c.Assert(resp.RequestId, gocheck.Equals, "7347261f-97df-11e2-8756-35eEXAMPLE")
}
Exemple #26
0
func (s *S) TestDescribeAdjustmentTypes(c *gocheck.C) {
	testServer.Response(200, nil, DescribeAdjustmentTypesResponse)
	resp, err := s.as.DescribeAdjustmentTypes()
	c.Assert(err, gocheck.IsNil)
	values := testServer.WaitRequest().PostForm
	c.Assert(values.Get("Version"), gocheck.Equals, "2011-01-01")
	c.Assert(values.Get("Action"), gocheck.Equals, "DescribeAdjustmentTypes")
	c.Assert(resp.RequestId, gocheck.Equals, "cc5f0337-b694-11e2-afc0-6544dEXAMPLE")
	c.Assert(resp.AdjustmentTypes, gocheck.DeepEquals, []AdjustmentType{{"ChangeInCapacity"}, {"ExactCapacity"}, {"PercentChangeInCapacity"}})
}
Exemple #27
0
func (s *ClientTests) TestGetNotFound(c *gocheck.C) {
	b := s.s3.Bucket("goamz-" + s.s3.Auth.AccessKey)
	data, err := b.Get("non-existent")

	s3err, _ := err.(*s3.Error)
	c.Assert(s3err, gocheck.NotNil)
	c.Assert(s3err.StatusCode, gocheck.Equals, 404)
	c.Assert(s3err.Code, gocheck.Equals, "NoSuchBucket")
	c.Assert(s3err.Message, gocheck.Equals, "The specified bucket does not exist")
	c.Assert(data, gocheck.IsNil)
}
Exemple #28
0
func (s *ClientTests) TestCreateUserError(c *gocheck.C) {
	_, err := s.iam.CreateUser("gopher", "/gopher/")
	c.Assert(err, gocheck.IsNil)
	defer s.iam.DeleteUser("gopher")
	_, err = s.iam.CreateUser("gopher", "/")
	iamErr, ok := err.(*iam.Error)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(iamErr.StatusCode, gocheck.Equals, 409)
	c.Assert(iamErr.Code, gocheck.Equals, "EntityAlreadyExists")
	c.Assert(iamErr.Message, gocheck.Equals, "User with name gopher already exists.")
}
Exemple #29
0
func (s *S) TestPutAlarmInvalidComapirsonOperator(c *gocheck.C) {
	testServer.Response(200, nil, "<RequestId>123</RequestId>")

	alarm := getTestAlarm()

	alarm.ComparisonOperator = "LessThan"

	_, err := s.cw.PutMetricAlarm(alarm)
	c.Assert(err, gocheck.NotNil)
	c.Assert(err.Error(), gocheck.Equals, "ComparisonOperator is not valid")
}
Exemple #30
0
func (s *S) TestPutAlarmInvalidStatistic(c *gocheck.C) {
	testServer.Response(200, nil, "<RequestId>123</RequestId>")

	alarm := getTestAlarm()

	alarm.Statistic = "Count"

	_, err := s.cw.PutMetricAlarm(alarm)
	c.Assert(err, gocheck.NotNil)
	c.Assert(err.Error(), gocheck.Equals, "Invalid statistic value supplied")
}