File: auth_test.go

package info (click to toggle)
golang-github-xenolf-lego 4.9.1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,076 kB
  • sloc: xml: 533; makefile: 130; sh: 18
file content (44 lines) | stat: -rw-r--r-- 1,022 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
package internal

import (
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestNewTokenTransport_success(t *testing.T) {
	apiKey := "api"
	secretKey := "secret"

	transport, err := NewTokenTransport(apiKey, secretKey)
	require.NoError(t, err)
	assert.NotNil(t, transport)
}

func TestNewTokenTransport_missing_credentials(t *testing.T) {
	apiKey := ""
	secretKey := ""

	transport, err := NewTokenTransport(apiKey, secretKey)
	require.Error(t, err)
	assert.Nil(t, transport)
}

func TestTokenTransport_RoundTrip(t *testing.T) {
	t.Skip("Skip during Debian build (no access to the network)")
	apiKey := "api"
	secretKey := "secret"

	transport, err := NewTokenTransport(apiKey, secretKey)
	require.NoError(t, err)

	req := httptest.NewRequest(http.MethodGet, "http://example.com", nil)

	resp, err := transport.RoundTrip(req)
	require.NoError(t, err)

	assert.Regexp(t, `api:[^:]{28}:\d{13}`, resp.Request.Header.Get(securityTokenHeader))
}