github.com/blend/go-sdk@v1.20220411.3/r2/main_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package r2 9 10 import ( 11 "fmt" 12 "io" 13 "net/http" 14 "net/http/httptest" 15 "time" 16 ) 17 18 type MockTracer struct { 19 StartHandler func(*http.Request) 20 FinishHandler func(*http.Request, *http.Response, time.Time, error) 21 } 22 23 func (mt MockTracer) Start(req *http.Request) TraceFinisher { 24 if mt.StartHandler != nil { 25 mt.StartHandler(req) 26 } 27 return MockTraceFinisher{ 28 Tracer: mt, 29 } 30 } 31 32 type MockTraceFinisher struct { 33 Tracer MockTracer 34 } 35 36 func (mtf MockTraceFinisher) Finish(req *http.Request, res *http.Response, t time.Time, err error) { 37 if mtf.Tracer.FinishHandler != nil { 38 mtf.Tracer.FinishHandler(req, res, t, err) 39 } 40 } 41 42 func readString(r io.Reader) string { 43 contents, _ := io.ReadAll(r) 44 return string(contents) 45 } 46 47 func mockServerOK() *httptest.Server { 48 return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 49 w.WriteHeader(http.StatusOK) 50 fmt.Fprintf(w, "OK!\n") 51 })) 52 } 53 54 var clientCert = []byte(`-----BEGIN CERTIFICATE----- 55 MIIDCzCCAfOgAwIBAgIQbU6bmWZG5fRA5rxB7jf9czANBgkqhkiG9w0BAQsFADAA 56 MCAYDzAwMDEwMTAxMDAwMDAwWhcNMjkwNTAyMDAwMDMzWjArMSkwJwYDVQQDEyAx 57 YzljNjViYWE0ZTU0MzdlYmE1NmQxMzRhMGU2ZWVjYzCCASIwDQYJKoZIhvcNAQEB 58 BQADggEPADCCAQoCggEBANd3YWl2ksmmVXlcbb/NXXiL6rjO54QOiD+Pftb/jJZv 59 zfazyF+rq8/4wSahh3qXm/i1yNHxmg4Iv673OizYw7viIzdMDo9TWypiPXHXJ8K0 60 iRBCZ8CeWcUK2I6dM2jzgmy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X/zggtAgAP93OvHw7GUMmcJPFYnCi3q2wY8L0342OOxiqcY 79 FGNeAvuFHGFiLoRRZwh0jAg2jMdkjPADyIwr6Wt/hYjrCJPYGel7DXF/RP3wsaIC 80 IM97lhnPb6f1tRWrvq774Gf0FL3cbJJoqC1mfeb+5hmSmHpX9ky6FudxIvviXLtT 81 mSzskHa1TcV5bNV9PzQpuRajwBk3NhH5NbwpIqT3IZ/ZoTZQ3y8CAwEAAaMjMCEw 82 DgYDVR0PAQH/BAQDAgKkMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQAD 83 ggEBACJTJe29CVo3qhFMcOKvKvZr6sCbXCtHr4fUI126AWPpUiUIOO12H8VvMgAy 84 boouth25FK/orgbqDlbjeVPaSKDyE+smkgyzB+URSdFK0u6U1+ON/aQimdMRamme 85 GzxIhu3cDMWuanC61ND91hYzakgPJEDXF+RfUi7ngGn30e8QLb0EwByjD99SJnak 86 lyFm5+SNAkOkZZ6Vc3CalFkaCgzehzuQTLImv2SFg1W3DiFQ90A572Qn3u+cj6+7 87 tUcjUZrzhHC0unYqqCb7KbJvNotAXT+kYq5FDVifeH+j09mzZ/SXCkTMtko0i0+m 88 dg8HIlKx9z1Bxys5Ko5hGpupXDY= 89 -----END CERTIFICATE----- 90 `) 91 92 var clientKey = []byte(`-----BEGIN RSA PRIVATE KEY----- 93 MIIEowIBAAKCAQEA13dhaXaSyaZVeVxtv81deIvquM7nhA6IP49+1v+Mlm/N9rPI 94 X6urz/jBJqGHepeb+LXI0fGaDgi/rvc6LNjDu+IjN0wOj1NbKmI9cdcnwrSJEEJn 95 wJ5ZxQrYjp0zaPOCbI4v/sFe024elHQFXFWkVH6iIaAisrwnwbHz62734ePWse+q 96 3yBiaDOOPCikI98z1n3y0GegEDcK3GH6KxEXay6Zh2r6RC3WYhzIQzVLPGq8mNfn 97 QpdBDao6vEf+QlAWy3I3DC0IjfEhF9wDNhGjUEOQCaFRvsNJNkSQWhw3yqMSM80B 98 UlE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5MPNOLe7VtJqDecbrK1TJpVyBT958Z5YL01AC7vO1/930G 115 f9T5AoGBALYDPM9zZDtbbh7SW/dpKpTS6BAm229gXLsMNRtmvAP3TZ4CgFuayIay 116 IVg93a56rlerNoUfafYkFNjy8xwNR734qtpCxn11L0L7gJtBW3/AUZIL+y3OwqtY 117 L8KvXHCoQKhC9uOMhb0Pju/4q3izTWrHnzPgLei+yDy1u+piDraf 118 -----END RSA PRIVATE KEY----- 119 `)