1
0
mirror of https://github.com/go-acme/lego.git synced 2024-11-29 01:42:09 +02:00

enhance the WithLiveTestRequirements algorithm (#681)

* refactor: migrate test to envTest.

* refactor: enforce WithLiveTestRequirements logic.

* chore: remove gometalinter.

* fix: godoc.

* doc: add Docker badge.
This commit is contained in:
Ludovic Fernandez 2018-10-18 22:32:00 +02:00 committed by GitHub
parent d775f2bcd5
commit 1d1b08ac15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 63 deletions

View File

@ -1,25 +0,0 @@
{
"Vendor": true,
"Test": true,
"Sort": [
"path",
"line",
"column",
"linter",
"severity"
],
"Cyclo": 12,
"Enable": [
"gotypex",
"varcheck",
"gotype",
"interfacer",
"misspell",
"ineffassign",
"golint",
"vet",
"gosimple"
],
"Exclude": [],
"Deadline": "2m"
}

View File

@ -2,8 +2,9 @@
Let's Encrypt client and ACME library written in Go
[![GoDoc](https://godoc.org/github.com/xenolf/lego/acme?status.svg)](https://godoc.org/github.com/xenolf/lego/acme)
[![GoDoc](https://godoc.org/github.com/xenolf/lego?status.svg)](https://godoc.org/github.com/xenolf/lego/acme)
[![Build Status](https://travis-ci.org/xenolf/lego.svg?branch=master)](https://travis-ci.org/xenolf/lego)
[![Docker Pulls](https://img.shields.io/docker/pulls/xenolf/lego.svg)](https://hub.docker.com/r/xenolf/lego/)
[![Dev Chat](https://img.shields.io/badge/dev%20chat-gitter-blue.svg?label=dev+chat)](https://gitter.im/xenolf/lego)
[![Beerpay](https://beerpay.io/xenolf/lego/badge.svg)](https://beerpay.io/xenolf/lego)
@ -20,8 +21,7 @@ To install from source, just run:
go get -u github.com/xenolf/lego
```
To build lego inside a Docker container, just run
To build lego inside a Docker container, just run:
```bash
docker build -t lego .
```

View File

@ -45,7 +45,12 @@ func (e *EnvTest) WithDomain(key string) *EnvTest {
// Replaces the default behavior (all keys are required).
func (e *EnvTest) WithLiveTestRequirements(keys ...string) *EnvTest {
var countValuedVars int
for _, key := range keys {
if e.domainKey != key && !e.isManagedKey(key) {
panic(fmt.Sprintf("Unauthorized action, the env var %s is not managed or it's not the key of the domain.", key))
}
if _, ok := e.values[key]; ok {
countValuedVars++
}
@ -120,15 +125,15 @@ func (e *EnvTest) liveTestExtra() bool {
// Not related to the main environment variables.
func (e *EnvTest) Apply(envVars map[string]string) {
for key, value := range envVars {
if e.isManagedKey(key) {
if len(value) == 0 {
os.Unsetenv(key)
} else {
os.Setenv(key, value)
}
} else {
if !e.isManagedKey(key) {
panic(fmt.Sprintf("Unauthorized action, the env var %s is not managed.", key))
}
if len(value) == 0 {
os.Unsetenv(key)
} else {
os.Setenv(key, value)
}
}
}

View File

@ -1,3 +1,4 @@
// Package auroradns implements a DNS provider for solving the DNS-01 challenge using Aurora DNS.
package auroradns
import (

View File

@ -1,51 +1,40 @@
package dns
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/xenolf/lego/providers/dns/exoscale"
"github.com/xenolf/lego/platform/tester"
"github.com/xenolf/lego/providers/dns/exec"
)
var (
apiKey string
apiSecret string
)
func init() {
apiSecret = os.Getenv("EXOSCALE_API_SECRET")
apiKey = os.Getenv("EXOSCALE_API_KEY")
}
func restoreExoscaleEnv() {
os.Setenv("EXOSCALE_API_KEY", apiKey)
os.Setenv("EXOSCALE_API_SECRET", apiSecret)
}
var envTest = tester.NewEnvTest("EXEC_PATH")
func TestKnownDNSProviderSuccess(t *testing.T) {
defer restoreExoscaleEnv()
os.Setenv("EXOSCALE_API_KEY", "abc")
os.Setenv("EXOSCALE_API_SECRET", "123")
defer envTest.RestoreEnv()
envTest.Apply(map[string]string{
"EXEC_PATH": "abc",
})
provider, err := NewDNSChallengeProviderByName("exoscale")
provider, err := NewDNSChallengeProviderByName("exec")
require.NoError(t, err)
assert.NotNil(t, provider)
assert.IsType(t, &exoscale.DNSProvider{}, provider, "Not loaded correct DNS provider")
assert.IsType(t, &exec.DNSProvider{}, provider, "The loaded DNS provider doesn't have the expected type.")
}
func TestKnownDNSProviderError(t *testing.T) {
defer restoreExoscaleEnv()
os.Setenv("EXOSCALE_API_KEY", "")
os.Setenv("EXOSCALE_API_SECRET", "")
defer envTest.RestoreEnv()
envTest.ClearEnv()
_, err := NewDNSChallengeProviderByName("exoscale")
provider, err := NewDNSChallengeProviderByName("exec")
assert.Error(t, err)
assert.Nil(t, provider)
}
func TestUnknownDNSProvider(t *testing.T) {
_, err := NewDNSChallengeProviderByName("foobar")
provider, err := NewDNSChallengeProviderByName("foobar")
assert.Error(t, err)
assert.Nil(t, provider)
}

View File

@ -1,3 +1,4 @@
// Package dnsmadeeasy implements a DNS provider for solving the DNS-01 challenge using DNS Made Easy.
package dnsmadeeasy
import (

View File

@ -1,4 +1,4 @@
// Package dreamhost Adds lego support for http://dreamhost.com DNS updates
// Package dreamhost implements a DNS provider for solving the DNS-01 challenge using DreamHost.
// See https://help.dreamhost.com/hc/en-us/articles/217560167-API_overview
// and https://help.dreamhost.com/hc/en-us/articles/217555707-DNS-API-commands for the API spec.
package dreamhost

View File

@ -1,4 +1,4 @@
// Package duckdns Adds lego support for http://duckdns.org.
// Package duckdns implements a DNS provider for solving the DNS-01 challenge using DuckDNS.
// See http://www.duckdns.org/spec.jsp for more info on updating TXT records.
package duckdns