File: customizations_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.49.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312,636 kB
  • sloc: makefile: 120
file content (115 lines) | stat: -rw-r--r-- 3,025 bytes parent folder | download | duplicates (2)
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
//go:build !integration
// +build !integration

package glacier_test

import (
	"bytes"
	"testing"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/awsutil"
	"github.com/aws/aws-sdk-go/awstesting/unit"
	"github.com/aws/aws-sdk-go/service/glacier"
)

var (
	payloadBuf = func() *bytes.Reader {
		buf := make([]byte, 5767168) // 5.5MB buffer
		for i := range buf {
			buf[i] = '0' // Fill with zero characters
		}
		return bytes.NewReader(buf)
	}()

	svc = glacier.New(unit.Session)
)

func TestCustomizations(t *testing.T) {
	req, _ := svc.UploadArchiveRequest(&glacier.UploadArchiveInput{
		VaultName: aws.String("vault"),
		Body:      payloadBuf,
	})
	err := req.Build()
	if err != nil {
		t.Errorf("expect no err, got %v", err)
	}

	// Sets API version
	if e, a := req.ClientInfo.APIVersion, req.HTTPRequest.Header.Get("x-amz-glacier-version"); e != a {
		t.Errorf("expect %v, got %v", e, a)
	}

	// Sets Account ID
	v, _ := awsutil.ValuesAtPath(req.Params, "AccountId")
	if e, a := "-", *(v[0].(*string)); e != a {
		t.Errorf("expect %v, got %v", e, a)
	}

	// Computes checksums
	linear := "68aff0c5a91aa0491752bfb96e3fef33eb74953804f6a2f7b708d5bcefa8ff6b"
	tree := "154e26c78fd74d0c2c9b3cc4644191619dc4f2cd539ae2a74d5fd07957a3ee6a"
	if e, a := linear, req.HTTPRequest.Header.Get("x-amz-content-sha256"); e != a {
		t.Errorf("expect %v, got %v", e, a)
	}
	if e, a := tree, req.HTTPRequest.Header.Get("x-amz-sha256-tree-hash"); e != a {
		t.Errorf("expect %v, got %v", e, a)
	}
}

func TestShortcircuitTreehash(t *testing.T) {
	req, _ := svc.UploadArchiveRequest(&glacier.UploadArchiveInput{
		VaultName: aws.String("vault"),
		Body:      payloadBuf,
		Checksum:  aws.String("000"),
	})
	err := req.Build()
	if err != nil {
		t.Errorf("expect no err, got %v", err)
	}

	if e, a := "000", req.HTTPRequest.Header.Get("x-amz-sha256-tree-hash"); e != a {
		t.Errorf("expect %v, got %v", e, a)
	}
}

func TestFillAccountIDWithNilStruct(t *testing.T) {
	req, _ := svc.ListVaultsRequest(nil)
	err := req.Build()
	if err != nil {
		t.Errorf("expect no err, got %v", err)
	}

	empty := "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"

	// Sets Account ID
	v, _ := awsutil.ValuesAtPath(req.Params, "AccountId")
	if e, a := "-", *(v[0].(*string)); e != a {
		t.Errorf("expect %v, got %v", e, a)
	}

	// Does not set tree hash
	if e, a := empty, req.HTTPRequest.Header.Get("x-amz-content-sha256"); e != a {
		t.Errorf("expect %v, got %v", e, a)
	}
	if e, a := "", req.HTTPRequest.Header.Get("x-amz-sha256-tree-hash"); e != a {
		t.Errorf("expect %v, got %v", e, a)
	}
}

func TestHashOnce(t *testing.T) {
	req, _ := svc.UploadArchiveRequest(&glacier.UploadArchiveInput{
		VaultName: aws.String("vault"),
		Body:      payloadBuf,
	})
	req.HTTPRequest.Header.Set("X-Amz-Sha256-Tree-Hash", "0")

	err := req.Build()
	if err != nil {
		t.Errorf("expect no err, got %v", err)
	}

	if e, a := "0", req.HTTPRequest.Header.Get("x-amz-sha256-tree-hash"); e != a {
		t.Errorf("expect %v, got %v", e, a)
	}
}