Skip to content

Commit

Permalink
Merge pull request #11 from aktsk/add-server-test
Browse files Browse the repository at this point in the history
Add server_test.go
  • Loading branch information
mizzy authored Apr 10, 2018
2 parents 6dd3c8b + 101d970 commit 67b6401
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package server

import (
"bytes"
"crypto/x509"
"encoding/json"
"encoding/pem"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"

"github.com/aktsk/nolmandy/receipt"
)

func TestServer(t *testing.T) {
certDER, _ := pem.Decode([]byte(certificate))
cert, err := x509.ParseCertificate(certDER.Bytes)
if err != nil {
t.Fatal(err)
}

s := httptest.NewServer(http.HandlerFunc(Parse(cert)))
defer s.Close()

req := Request{ReceiptData: receiptData}
reqBody, err := json.Marshal(req)
if err != nil {
t.Fatal(err)
}

resp, err := http.Post(s.URL, "application/json", bytes.NewReader(reqBody))
if err != nil {
t.Fatal(err)
}

respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}

var result receipt.Result
json.Unmarshal(respBody, &result)

if result.Status != 0 {
t.Fatal("Status is not 0")
}

rcpt := result.Receipt

if rcpt.ReceiptType != "ProductionSandbox" {
t.Fatalf("Wrong receipt_type: %s", rcpt.ReceiptType)
}
}

var receiptData = `
MIIHeQYJKoZIhvcNAQcCoIIHajCCB2YCAQExCTAHBgUrDgMCGjCCBDYGCSqGSIb3DQEHAaCCBCcEggQjMIIEHzAbAgEAAgEABBMTEVByb2R1Y3Rpb25TYW5kYm94MCACAQICAQAEGBMWanAuYWt0c2sua2FsdmFkb3MudGVzdDAeAgEMAgEABBYTFDIwMTgtMDItMTBUMTc6Mzc6MDBaMIIBIgIBEQIBAASCARgwggEUMAwCAgalAgEABAMCAQAwJgICBqYCAQAEHRMbanAuYWt0c2sua2FsdmFkb3MudGVzdC5pYXAwMBoCAganAgEABBETDzIyMDAwMDM1MDcyOTk3MDAfAgIGqAI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Rmj/t1xy329ElWAwbtTZkBQ1nivyKVJH/IGbnPr51FAZ5JEm5xntGf`

var certificate = `
-----BEGIN CERTIFICATE-----
MIIB3TCCAUagAwIBAgIEcotswjANBgkqhkiG9w0BAQsFADAoMRAwDgYDVQQKEwdB
Y21lIENvMRQwEgYDVQQDEwtUZXN0IElzc3VlcjAgFw0xODA0MDIwNDA2MjlaGA8z
ODQzMDQwMjA0MDYyOVowKDEQMA4GA1UEChMHQWNtZSBDbzEUMBIGA1UEAxMLVGVz
dCBJc3N1ZXIwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMb89jkLRDjud2Xt
tYoXscWCGTKAr+TYv7dwk7YXqabv4bhH5X15sbg9cp5UWZzu7ygoX4+N/48Aa/AZ
Sh8ppQZYpa73ximUesF8W+ZDXeOsexoPuRyXKltjXX/eLklBldVBB8Weyip4WhmG
TCguTUW5eFPtseIEBHxto12jB6gnAgMBAAGjEjAQMA4GA1UdDwEB/wQEAwICpDAN
BgkqhkiG9w0BAQsFAAOBgQC+abUGkSNC5n6r4TjbCrAHZcFI0yCcK38fS2g9c7lb
VcvltNox2SWL9oyjybdzm1iZoVtsHXuQ8RKszdVKCh7N1RUOGDgtuwfP2XnKCKoP
W9VfLKZ+Y4YnouEZBUjsS39dgLC2EJ66e3kWfCrR6HNsSWwE0A3mVnfNUwLvgtH/
QQ==
-----END CERTIFICATE-----`

0 comments on commit 67b6401

Please sign in to comment.