2022-04-27 10:51:06 +00:00
|
|
|
package orchestration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
2022-06-13 16:44:27 +00:00
|
|
|
"time"
|
2022-04-27 10:51:06 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2022-06-13 16:44:27 +00:00
|
|
|
"github.com/cloudflare/cloudflared/config"
|
2022-04-27 10:51:06 +00:00
|
|
|
"github.com/cloudflare/cloudflared/ingress"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestNewLocalConfig_MarshalJSON tests that we are able to converte a compiled and validated config back
|
|
|
|
// into an "unvalidated" format which is compatible with Remote Managed configurations.
|
|
|
|
func TestNewLocalConfig_MarshalJSON(t *testing.T) {
|
|
|
|
rawConfig := []byte(`
|
|
|
|
{
|
|
|
|
"originRequest": {
|
|
|
|
"connectTimeout": 160,
|
|
|
|
"httpHostHeader": "default"
|
|
|
|
},
|
|
|
|
"ingress": [
|
|
|
|
{
|
|
|
|
"hostname": "tun.example.com",
|
|
|
|
"service": "https://localhost:8000"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"hostname": "*",
|
|
|
|
"service": "https://localhost:8001",
|
|
|
|
"originRequest": {
|
|
|
|
"connectTimeout": 121,
|
|
|
|
"tlsTimeout": 2,
|
|
|
|
"noHappyEyeballs": false,
|
|
|
|
"tcpKeepAlive": 2,
|
|
|
|
"keepAliveConnections": 2,
|
|
|
|
"keepAliveTimeout": 2,
|
|
|
|
"httpHostHeader": "def",
|
|
|
|
"originServerName": "b2",
|
|
|
|
"caPool": "/tmp/path1",
|
|
|
|
"noTLSVerify": false,
|
|
|
|
"disableChunkedEncoding": false,
|
|
|
|
"bastionMode": false,
|
|
|
|
"proxyAddress": "interface",
|
|
|
|
"proxyPort": 200,
|
|
|
|
"proxyType": "",
|
|
|
|
"ipRules": [
|
|
|
|
{
|
|
|
|
"prefix": "10.0.0.0/16",
|
|
|
|
"ports": [3000, 3030],
|
|
|
|
"allow": false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"prefix": "192.16.0.0/24",
|
|
|
|
"ports": [5000, 5050],
|
|
|
|
"allow": true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2022-06-13 16:44:27 +00:00
|
|
|
],
|
|
|
|
"warp-routing": {
|
|
|
|
"enabled": true,
|
|
|
|
"connectTimeout": 1
|
|
|
|
}
|
2022-04-27 10:51:06 +00:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
var expectedConfig ingress.RemoteConfig
|
|
|
|
err := json.Unmarshal(rawConfig, &expectedConfig)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
c := &newLocalConfig{
|
|
|
|
RemoteConfig: expectedConfig,
|
|
|
|
ConfigurationFlags: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonSerde, err := json.Marshal(c)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-06-13 16:44:27 +00:00
|
|
|
var remoteConfig ingress.RemoteConfig
|
|
|
|
err = json.Unmarshal(jsonSerde, &remoteConfig)
|
2022-04-27 10:51:06 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-06-13 16:44:27 +00:00
|
|
|
require.Equal(t, remoteConfig.WarpRouting, ingress.WarpRoutingConfig{
|
|
|
|
Enabled: true,
|
|
|
|
ConnectTimeout: config.CustomDuration{
|
|
|
|
Duration: time.Second,
|
|
|
|
},
|
|
|
|
TCPKeepAlive: config.CustomDuration{
|
|
|
|
Duration: 30 * time.Second, // default value is 30 seconds
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.Equal(t, remoteConfig.Ingress.Rules, expectedConfig.Ingress.Rules)
|
2022-04-27 10:51:06 +00:00
|
|
|
}
|