forked from TrueCloudLab/lego
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:
parent
d775f2bcd5
commit
1d1b08ac15
8 changed files with 34 additions and 63 deletions
|
@ -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"
|
|
||||||
}
|
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
Let's Encrypt client and ACME library written in Go
|
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)
|
[![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)
|
[![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)
|
[![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
|
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
|
```bash
|
||||||
docker build -t lego .
|
docker build -t lego .
|
||||||
```
|
```
|
||||||
|
|
|
@ -45,7 +45,12 @@ func (e *EnvTest) WithDomain(key string) *EnvTest {
|
||||||
// Replaces the default behavior (all keys are required).
|
// Replaces the default behavior (all keys are required).
|
||||||
func (e *EnvTest) WithLiveTestRequirements(keys ...string) *EnvTest {
|
func (e *EnvTest) WithLiveTestRequirements(keys ...string) *EnvTest {
|
||||||
var countValuedVars int
|
var countValuedVars int
|
||||||
|
|
||||||
for _, key := range keys {
|
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 {
|
if _, ok := e.values[key]; ok {
|
||||||
countValuedVars++
|
countValuedVars++
|
||||||
}
|
}
|
||||||
|
@ -120,15 +125,15 @@ func (e *EnvTest) liveTestExtra() bool {
|
||||||
// Not related to the main environment variables.
|
// Not related to the main environment variables.
|
||||||
func (e *EnvTest) Apply(envVars map[string]string) {
|
func (e *EnvTest) Apply(envVars map[string]string) {
|
||||||
for key, value := range envVars {
|
for key, value := range envVars {
|
||||||
if e.isManagedKey(key) {
|
if !e.isManagedKey(key) {
|
||||||
|
panic(fmt.Sprintf("Unauthorized action, the env var %s is not managed.", key))
|
||||||
|
}
|
||||||
|
|
||||||
if len(value) == 0 {
|
if len(value) == 0 {
|
||||||
os.Unsetenv(key)
|
os.Unsetenv(key)
|
||||||
} else {
|
} else {
|
||||||
os.Setenv(key, value)
|
os.Setenv(key, value)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
panic(fmt.Sprintf("Unauthorized action, the env var %s is not managed.", key))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Package auroradns implements a DNS provider for solving the DNS-01 challenge using Aurora DNS.
|
||||||
package auroradns
|
package auroradns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -1,51 +1,40 @@
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"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 (
|
var envTest = tester.NewEnvTest("EXEC_PATH")
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestKnownDNSProviderSuccess(t *testing.T) {
|
func TestKnownDNSProviderSuccess(t *testing.T) {
|
||||||
defer restoreExoscaleEnv()
|
defer envTest.RestoreEnv()
|
||||||
os.Setenv("EXOSCALE_API_KEY", "abc")
|
envTest.Apply(map[string]string{
|
||||||
os.Setenv("EXOSCALE_API_SECRET", "123")
|
"EXEC_PATH": "abc",
|
||||||
|
})
|
||||||
|
|
||||||
provider, err := NewDNSChallengeProviderByName("exoscale")
|
provider, err := NewDNSChallengeProviderByName("exec")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, provider)
|
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) {
|
func TestKnownDNSProviderError(t *testing.T) {
|
||||||
defer restoreExoscaleEnv()
|
defer envTest.RestoreEnv()
|
||||||
os.Setenv("EXOSCALE_API_KEY", "")
|
envTest.ClearEnv()
|
||||||
os.Setenv("EXOSCALE_API_SECRET", "")
|
|
||||||
|
|
||||||
_, err := NewDNSChallengeProviderByName("exoscale")
|
provider, err := NewDNSChallengeProviderByName("exec")
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
assert.Nil(t, provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnknownDNSProvider(t *testing.T) {
|
func TestUnknownDNSProvider(t *testing.T) {
|
||||||
_, err := NewDNSChallengeProviderByName("foobar")
|
provider, err := NewDNSChallengeProviderByName("foobar")
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
assert.Nil(t, provider)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Package dnsmadeeasy implements a DNS provider for solving the DNS-01 challenge using DNS Made Easy.
|
||||||
package dnsmadeeasy
|
package dnsmadeeasy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -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
|
// 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.
|
// and https://help.dreamhost.com/hc/en-us/articles/217555707-DNS-API-commands for the API spec.
|
||||||
package dreamhost
|
package dreamhost
|
||||||
|
|
|
@ -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.
|
// See http://www.duckdns.org/spec.jsp for more info on updating TXT records.
|
||||||
package duckdns
|
package duckdns
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue