File: main_ig_test.go

package info (click to toggle)
acmetool 0.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 792 kB
  • sloc: sh: 349; makefile: 105
file content (72 lines) | stat: -rw-r--r-- 2,464 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
71
72
// +build integration

package cli

import (
	"fmt"
	//"gopkg.in/hlandau/acmeapi.v2"
	"github.com/hlandau/acmetool/interaction"
	"github.com/hlandau/acmetool/responder"
	"github.com/hlandau/acmetool/storageops"
	"gopkg.in/hlandau/acmeapi.v2/pebbletest"
	"io/ioutil"
	"path/filepath"
	"strings"
	"testing"
)

type interceptor struct {
}

func (i *interceptor) Prompt(c *interaction.Challenge) (*interaction.Response, error) {
	switch c.UniqueID {
	case "acmetool-quickstart-choose-server":
		return &interaction.Response{Value: "url"}, nil
	case "acmetool-quickstart-enter-directory-url":
		return &interaction.Response{Value: "https://127.0.0.1:14000/dir"}, nil
	case "acmetool-quickstart-choose-method":
		return &interaction.Response{Value: "redirector"}, nil
	case "acme-enter-email":
		return &interaction.Response{Value: "nobody@example.com"}, nil
	case "acmetool-quickstart-complete":
		return &interaction.Response{}, nil
	case "acmetool-quickstart-install-cronjob", "acmetool-quickstart-install-haproxy-script", "acmetool-quickstart-install-redirector-systemd":
		return &interaction.Response{Cancelled: true}, nil
	default:
		if strings.HasPrefix(c.UniqueID, "acme-agreement:") {
			return &interaction.Response{}, nil
		}

		return nil, fmt.Errorf("unsupported challenge for interceptor: %v", c)
	}
}

func (i *interceptor) Status(info *interaction.StatusInfo) (interaction.StatusSink, error) {
	return nil, fmt.Errorf("status not supported")
}

func TestCLI(t *testing.T) {
	log.Warnf("This test requires a configured Boulder instance listening at http://127.0.0.1:4000/ and the ability to successfully complete challenges. You must change the Boulder configuration to use ports 80 and 5001. Also change the rate limits per certificate name. Consider ensuring that the user you run these tests as can write to %s and that that directory is served on port 80 /.well-known/acme-challenge/", responder.StandardWebrootPath)

	//acmeapi.TestingAllowHTTP = true
	storageops.InternalHTTPClient = pebbletest.HTTPClient

	interaction.Interceptor = &interceptor{}

	tmpDir, err := ioutil.TempDir("", "acmetool-test")
	if err != nil {
		panic(err)
	}

	*stateFlag = filepath.Join(tmpDir, "state")
	*hooksFlag = []string{filepath.Join(tmpDir, "hooks")}

	responder.InternalHTTPPort = 5002
	//responder.InternalTLSSNIPort = 5001
	cmdQuickstart()

	*wantArg = []string{"dom1.acmetool-test.devever.net", "dom2.acmetool-test.devever.net"}

	cmdWant()
	cmdReconcile()
}