File: api_ig_test.go

package info (click to toggle)
acmetool 0.0.58-4~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 732 kB
  • sloc: sh: 188; makefile: 78
file content (70 lines) | stat: -rw-r--r-- 1,457 bytes parent folder | download | duplicates (3)
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
// +build integration

package acmeapi

import (
	"crypto"
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rand"
	"crypto/rsa"
	"golang.org/x/net/context"
	"testing"
)

func testAPIWithKey(t *testing.T, pk crypto.PrivateKey) {
	cl := Client{
		DirectoryURL: "http://127.0.0.1:4000/directory",
	}
	cl.AccountKey = pk
	agreementURIs := map[string]struct{}{
		"http://boulder:4000/terms/v1": {},
	}
	reg := &Registration{
		ContactURIs: []string{
			"mailto:nobody@localhost",
		},
	}

	err := cl.AgreeRegistration(reg, agreementURIs, context.TODO())
	if err != nil {
		t.Fatalf("couldn't upsert registration: %v", err)
	}

	auth, err := cl.NewAuthorization("dom1.acmetool-test.devever.net", context.TODO())
	if err != nil {
		t.Fatalf("couldn't create authorization: %v", err)
	}

	err = cl.WaitLoadAuthorization(auth, context.TODO())
	if err != nil {
		t.Fatalf("couldn't load authorization")
	}

	err = cl.WaitLoadChallenge(auth.Challenges[0], context.TODO())
	if err != nil {
		t.Fatalf("couldn't load challenge")
	}

	// TODO
	//cl.RespondToChallenge
	//cl.RequestCertificate
}

func TestAPIIntegration(t *testing.T) {
	TestingAllowHTTP = true

	rsaPK, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		t.Fatalf("couldn't generate RSA key: %v", err)
	}

	testAPIWithKey(t, rsaPK)

	ecdsaPK, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
	if err != nil {
		t.Fatalf("couldn't generate ECDSA key: %v", err)
	}

	testAPIWithKey(t, ecdsaPK)
}