github.com/aavshr/aws-sdk-go@v1.41.3/service/cognitoidentity/customizations_test.go (about)

     1  //go:build go1.8
     2  // +build go1.8
     3  
     4  package cognitoidentity_test
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/aavshr/aws-sdk-go/aws"
    10  	"github.com/aavshr/aws-sdk-go/aws/credentials"
    11  	"github.com/aavshr/aws-sdk-go/aws/request"
    12  	"github.com/aavshr/aws-sdk-go/awstesting/unit"
    13  	"github.com/aavshr/aws-sdk-go/service/cognitoidentity"
    14  )
    15  
    16  var svc = cognitoidentity.New(unit.Session)
    17  
    18  func TestUnsignedRequests(t *testing.T) {
    19  	cases := map[string]struct {
    20  		ReqFn func() *request.Request
    21  	}{
    22  		"GetId": {
    23  			ReqFn: func() *request.Request {
    24  				req, _ := svc.GetIdRequest(&cognitoidentity.GetIdInput{
    25  					IdentityPoolId: aws.String("IdentityPoolId"),
    26  				})
    27  				return req
    28  			},
    29  		},
    30  		"GetOpenIdToken": {
    31  			ReqFn: func() *request.Request {
    32  				req, _ := svc.GetOpenIdTokenRequest(&cognitoidentity.GetOpenIdTokenInput{
    33  					IdentityId: aws.String("IdentityId"),
    34  				})
    35  				return req
    36  			},
    37  		},
    38  		"UnlinkIdentity": {
    39  			ReqFn: func() *request.Request {
    40  				req, _ := svc.UnlinkIdentityRequest(&cognitoidentity.UnlinkIdentityInput{
    41  					IdentityId:     aws.String("IdentityId"),
    42  					Logins:         map[string]*string{},
    43  					LoginsToRemove: []*string{},
    44  				})
    45  				return req
    46  			},
    47  		},
    48  		"GetCredentialsForIdentity": {
    49  			ReqFn: func() *request.Request {
    50  				req, _ := svc.GetCredentialsForIdentityRequest(&cognitoidentity.GetCredentialsForIdentityInput{
    51  					IdentityId: aws.String("IdentityId"),
    52  				})
    53  				return req
    54  			},
    55  		},
    56  	}
    57  
    58  	for cn, c := range cases {
    59  		t.Run(cn, func(t *testing.T) {
    60  			req := c.ReqFn()
    61  			err := req.Sign()
    62  			if err != nil {
    63  				t.Errorf("expected no error, but received %v", err)
    64  			}
    65  
    66  			if e, a := credentials.AnonymousCredentials, req.Config.Credentials; e != a {
    67  				t.Errorf("expect request to use anonymous credentias, %v", a)
    68  			}
    69  
    70  			if e, a := "", req.HTTPRequest.Header.Get("Authorization"); e != a {
    71  				t.Errorf("expected empty value '%v', but received, %v", e, a)
    72  			}
    73  		})
    74  	}
    75  }