Add Vault certificate rotation operator
This commit is contained in:
parent
c685229437
commit
8009b5fd9c
1 changed files with 1013 additions and 0 deletions
35
internal/rotator/vault_test.go
Normal file
35
internal/rotator/vault_test.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package rotator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVaultLogin(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
|
||||
if request.URL.Path != "/v1/auth/kubernetes/login" {
|
||||
http.NotFound(response, request)
|
||||
return
|
||||
}
|
||||
var body map[string]string
|
||||
if err := json.NewDecoder(request.Body).Decode(&body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if body["role"] != "role" || body["jwt"] != "jwt" {
|
||||
t.Fatalf("unexpected login body: %#v", body)
|
||||
}
|
||||
_ = json.NewEncoder(response).Encode(map[string]any{"auth": map[string]string{"client_token": "token"}})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
token, err := (vaultClient{baseURL: server.URL, client: server.Client()}).login(context.Background(), "role", "jwt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if token != "token" {
|
||||
t.Fatalf("unexpected token: %s", token)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue