lego/providers/http/webroot/webroot_test.go

41 lines
912 B
Go
Raw Permalink Normal View History

2019-03-11 16:56:48 +00:00
package webroot
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestHTTPProvider(t *testing.T) {
webroot := "webroot"
domain := "domain"
token := "token"
keyAuth := "keyAuth"
challengeFilePath := webroot + "/.well-known/acme-challenge/" + token
2020-07-09 23:48:18 +00:00
require.NoError(t, os.MkdirAll(webroot+"/.well-known/acme-challenge", 0o777))
defer os.RemoveAll(webroot)
provider, err := NewHTTPProvider(webroot)
require.NoError(t, err)
err = provider.Present(domain, token, keyAuth)
require.NoError(t, err)
if _, err = os.Stat(challengeFilePath); os.IsNotExist(err) {
t.Error("Challenge file was not created in webroot")
}
var data []byte
2021-08-25 09:44:11 +00:00
data, err = os.ReadFile(challengeFilePath)
require.NoError(t, err)
dataStr := string(data)
assert.Equal(t, keyAuth, dataStr)
err = provider.CleanUp(domain, token, keyAuth)
require.NoError(t, err)
}