Fixes #898: Replace hashicorp and terraform references (#973)

Signed-off-by: Janos Bonic <86970079+janosdebugs@users.noreply.github.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
Janos
2023-12-08 14:03:09 +01:00
committed by GitHub
parent 1a7b68aa56
commit 15bef1428a
470 changed files with 1952 additions and 1878 deletions

View File

@@ -5,6 +5,7 @@ package remote
import (
"context"
"crypto/x509"
"fmt"
"io"
"net/http"
@@ -38,7 +39,7 @@ const (
)
var (
tfeHost = svchost.Hostname("app.terraform.io")
tfeHost = svchost.Hostname("app.example.com")
credsSrc = auth.StaticCredentialsSource(map[svchost.Hostname]map[string]interface{}{
tfeHost: {"token": testCred},
})
@@ -70,8 +71,8 @@ func testInput(t *testing.T, answers map[string]string) *mockInput {
func testBackendDefault(t *testing.T) (*Remote, func()) {
obj := cty.ObjectVal(map[string]cty.Value{
"hostname": cty.StringVal("app.terraform.io"),
"organization": cty.StringVal("hashicorp"),
"hostname": cty.StringVal("app.example.com"),
"organization": cty.StringVal("opentofu"),
"token": cty.NullVal(cty.String),
"workspaces": cty.ObjectVal(map[string]cty.Value{
"name": cty.StringVal("prod"),
@@ -83,8 +84,8 @@ func testBackendDefault(t *testing.T) (*Remote, func()) {
func testBackendNoDefault(t *testing.T) (*Remote, func()) {
obj := cty.ObjectVal(map[string]cty.Value{
"hostname": cty.StringVal("app.terraform.io"),
"organization": cty.StringVal("hashicorp"),
"hostname": cty.StringVal("app.example.com"),
"organization": cty.StringVal("opentofu"),
"token": cty.NullVal(cty.String),
"workspaces": cty.ObjectVal(map[string]cty.Value{
"name": cty.NullVal(cty.String),
@@ -96,7 +97,7 @@ func testBackendNoDefault(t *testing.T) (*Remote, func()) {
func testBackendNoOperations(t *testing.T) (*Remote, func()) {
obj := cty.ObjectVal(map[string]cty.Value{
"hostname": cty.StringVal("app.terraform.io"),
"hostname": cty.StringVal("app.example.com"),
"organization": cty.StringVal("no-operations"),
"token": cty.NullVal(cty.String),
"workspaces": cty.ObjectVal(map[string]cty.Value{
@@ -200,12 +201,11 @@ func testLocalBackend(t *testing.T, remote *Remote) backend.Enhanced {
return b
}
// testServer returns a *httptest.Server used for local testing.
func testServer(t *testing.T) *httptest.Server {
func getTestServerMux(t *testing.T) http.Handler {
mux := http.NewServeMux()
// Respond to service discovery calls.
mux.HandleFunc("/well-known/terraform.json", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/.well-known/terraform.json", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
io.WriteString(w, `{
"state.v2": "/api/v2/",
@@ -231,8 +231,8 @@ func testServer(t *testing.T) *httptest.Server {
w.Header().Set("TFP-API-Version", "2.4")
})
// Respond to the initial query to read the hashicorp org entitlements.
mux.HandleFunc("/api/v2/organizations/hashicorp/entitlement-set", func(w http.ResponseWriter, r *http.Request) {
// Respond to the initial query to read the opentofu org entitlements.
mux.HandleFunc("/api/v2/organizations/opentofu/entitlement-set", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/vnd.api+json")
io.WriteString(w, `{
"data": {
@@ -269,7 +269,7 @@ func testServer(t *testing.T) *httptest.Server {
}`)
})
// All tests that are assumed to pass will use the hashicorp organization,
// All tests that are assumed to pass will use the opentofu organization,
// so for all other organization requests we will return a 404.
mux.HandleFunc("/api/v2/organizations/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
@@ -282,11 +282,22 @@ func testServer(t *testing.T) *httptest.Server {
]
}`)
})
return httptest.NewServer(mux)
return mux
}
// testDisco returns a *disco.Disco mapping app.terraform.io and
// testServer returns a *httptest.Server used for local testing.
func testServer(t *testing.T) *httptest.Server {
return httptest.NewServer(getTestServerMux(t))
}
// testServerTLS returns a *httptest.Server used for local testing with TLS enabled.
func testServerTLS(t *testing.T) *httptest.Server {
ts := httptest.NewUnstartedServer(getTestServerMux(t))
ts.StartTLS()
return ts
}
// testDisco returns a *disco.Disco mapping app.example.com and
// localhost to a local test server.
func testDisco(s *httptest.Server) *disco.Disco {
services := map[string]interface{}{
@@ -296,9 +307,14 @@ func testDisco(s *httptest.Server) *disco.Disco {
}
d := disco.NewWithCredentialsSource(credsSrc)
d.SetUserAgent(httpclient.OpenTofuUserAgent(version.String()))
if s.TLS != nil {
certPool := x509.NewCertPool()
certPool.AddCert(s.Certificate())
d.Transport = httpclient.NewTransportWithCustomTrustedCertificates(certPool)
}
d.ForceHostServices(svchost.Hostname("app.terraform.io"), services)
d.ForceHostServices(svchost.Hostname("localhost"), services)
d.ForceHostServices("app.example.com", services)
d.ForceHostServices("localhost", services)
return d
}