2023-04-14 18:12:31 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2023-03-29 21:08:31 +00:00
|
|
|
package pki
|
2023-03-28 17:29:54 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAcmeNonces(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2023-03-29 18:22:48 +00:00
|
|
|
a := NewACMEState()
|
2023-05-23 19:44:05 +00:00
|
|
|
a.nonces.Initialize()
|
2023-03-28 17:29:54 +00:00
|
|
|
|
|
|
|
// Simple operation should succeed.
|
|
|
|
nonce, _, err := a.GetNonce()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, nonce)
|
|
|
|
|
|
|
|
require.True(t, a.RedeemNonce(nonce))
|
|
|
|
require.False(t, a.RedeemNonce(nonce))
|
|
|
|
|
|
|
|
// Redeeming in opposite order should work.
|
|
|
|
var nonces []string
|
|
|
|
for i := 0; i < len(nonce); i++ {
|
|
|
|
nonce, _, err = a.GetNonce()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, nonce)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := len(nonces) - 1; i >= 0; i-- {
|
|
|
|
nonce = nonces[i]
|
|
|
|
require.True(t, a.RedeemNonce(nonce))
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(nonces); i++ {
|
|
|
|
nonce = nonces[i]
|
|
|
|
require.False(t, a.RedeemNonce(nonce))
|
|
|
|
}
|
|
|
|
}
|