mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-12-09 13:46:07 +08:00
# Issue * New record type: "RP" (supported by BIND and GANDI_V5) * Cloudflare: CF_REDIRECT/CF_TEMP_REDIRECT now generate CF_SINGLE_REDIRECT records. All PAGE_RULE-based code is removed. PAGE_RULEs are deprecated at Cloudflare. (be careful when upgrading!) * New "v2" RecordConfig: RP and CF_SINGLE_REDIRECT are the only record types that use this method. It shifts most of the work out of JavaScript and into the Go code, making new record types easier to make, easier to test, and easier to use by providers. This opens the door to new things like a potential code-generator for rtypes. Converting existing rtypes will happen over the next year. * When only the TTL changes (MODIFY-TTL), the output lists the TTL change first, not at the end of the line where it is visually lost. * CF_REDIRECT/CF_TEMP_REDIRECT generate different rule "names". They will be updated the first time you "push" with this release. The order of the rules may also change. If you rules depend on a particular order, be very careful with this upgrade! Refactoring: * New "v2" RecordConfig: Record types using this new method simply package the parameters from dnsconfig.js statements like CF_REDIRECT(foo,bar) and send them (raw) to the Go code. The Go code does all processing, validation, etc. and turns them into RecordConfig that store all the rdata in `RecordConfig.F`. No more adding fields to RecordConfig for each new record type! * RecordConfig.IsModernType() returns true if the record uses the new v2 record mechanism. * PostProcess is now a method on DnsConfig and DomainConfig. * DOC: How to create new rtypes using the v2 method (incomplete) Other things: * Integration tests for CF "full proxy" are removed. This feature doesn't exist any more. * DEV: Debugger tips now includes VSCode advice * TESTING: The names of testgroup's can now have extra spaces to make data align better * CF_TEMP_REDIRECT/CF_REDIRECT is now a "builder" that generates CLOUDFLAREAPI_SINGLE_REDIRECT records. * And more! # Resolution --------- Co-authored-by: Jakob Ackermann <das7pad@outlook.com>
126 lines
3.4 KiB
Go
126 lines
3.4 KiB
Go
package main
|
|
|
|
// Functions for all tests in this directory.
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/StackExchange/dnscontrol/v4/pkg/credsfile"
|
|
"github.com/StackExchange/dnscontrol/v4/providers"
|
|
"github.com/StackExchange/dnscontrol/v4/providers/cloudflare"
|
|
)
|
|
|
|
var (
|
|
providerFlag = flag.String("provider", "", "Provider to run (if empty, deduced from -profile)")
|
|
profileFlag = flag.String("profile", "", "Entry in profiles.json to use (if empty, copied from -provider)")
|
|
enableCFWorkers = flag.Bool("cfworkers", true, "enable CF worker tests (default true)")
|
|
enableCFRedirectMode = flag.Bool("cfredirect", false, "enable CF SingleRedirect tests (default false)")
|
|
)
|
|
|
|
func init() {
|
|
testing.Init()
|
|
|
|
flag.Parse()
|
|
}
|
|
|
|
// ---
|
|
|
|
func panicOnErr(err error) {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func getProvider(t *testing.T) (providers.DNSServiceProvider, string, map[string]string) {
|
|
if *providerFlag == "" && *profileFlag == "" {
|
|
t.Log("No -provider or -profile specified")
|
|
return nil, "", nil
|
|
}
|
|
|
|
// Load the profile values
|
|
|
|
jsons, err := credsfile.LoadProviderConfigs("profiles.json")
|
|
if err != nil {
|
|
t.Fatalf("Error loading provider configs: %s", err)
|
|
}
|
|
|
|
// Which profile are we using? Use the profile but default to the provider.
|
|
targetProfile := *profileFlag
|
|
if targetProfile == "" {
|
|
targetProfile = *providerFlag
|
|
}
|
|
|
|
var profileName, profileType string
|
|
var cfg map[string]string
|
|
|
|
// Find the profile we want to use.
|
|
for p, c := range jsons {
|
|
if p == targetProfile {
|
|
cfg = c
|
|
profileName = p
|
|
profileType = cfg["TYPE"]
|
|
if profileType == "" {
|
|
t.Fatalf("profiles.json profile %q does not have a TYPE field", *profileFlag)
|
|
}
|
|
break
|
|
}
|
|
}
|
|
if profileName == "" {
|
|
t.Fatalf("Profile not found: -profile=%q -provider=%q", *profileFlag, *providerFlag)
|
|
return nil, "", nil
|
|
}
|
|
|
|
// Fill in -profile if blank.
|
|
if *profileFlag == "" {
|
|
*profileFlag = profileName
|
|
}
|
|
// Fill in -provider if blank.
|
|
if *providerFlag == "" {
|
|
*providerFlag = profileType
|
|
}
|
|
|
|
// Sanity check. If the user-specifed -provider flag doesn't match what was in the file, warn them.
|
|
if *providerFlag != profileType {
|
|
fmt.Printf("WARNING: -provider=%q does not match profile TYPE=%q. Using profile TYPE.\n", *providerFlag, profileType)
|
|
*providerFlag = profileType
|
|
}
|
|
|
|
// fmt.Printf("DEBUG flag=%q Profile=%q TYPE=%q\n", *providerFlag, profileName, profileType)
|
|
fmt.Printf("Testing Profile=%q (TYPE=%q)\n", profileName, profileType)
|
|
|
|
var metadata json.RawMessage
|
|
|
|
// CLOUDFLAREAPI tests related to CLOUDFLAREAPI_SINGLE_REDIRECT/CF_REDIRECT/CF_TEMP_REDIRECT
|
|
// requires metadata to enable this feature.
|
|
// In hindsight, I have no idea why this metadata flag is required to
|
|
// use this feature. Maybe because we didn't have the capabilities
|
|
// feature at the time?
|
|
if profileType == "CLOUDFLAREAPI" {
|
|
items := []string{}
|
|
if *enableCFWorkers {
|
|
items = append(items, `"manage_workers": true`)
|
|
}
|
|
if *enableCFRedirectMode {
|
|
items = append(items, `"manage_single_redirects": true`)
|
|
}
|
|
metadata = []byte(`{ ` + strings.Join(items, `, `) + ` }`)
|
|
}
|
|
|
|
provider, err := providers.CreateDNSProvider(profileType, cfg, metadata)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if profileType == "CLOUDFLAREAPI" && *enableCFWorkers {
|
|
// Cloudflare only. Will do nothing if provider != *cloudflareProvider.
|
|
if err := cloudflare.PrepareCloudflareTestWorkers(provider); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
return provider, cfg["domain"], cfg
|
|
}
|