diff --git a/api/default_test.go b/api/default_test.go index 571b4dbf0..4116cc4d2 100644 --- a/api/default_test.go +++ b/api/default_test.go @@ -9,16 +9,17 @@ import ( "github.com/stretchr/testify/require" ) -func TestOverrideApiConfig(t *testing.T) { +func setupConfigs() (*params.NodeConfig, *requests.APIConfig) { newNodeConfig := ¶ms.NodeConfig{ - APIModules: "test, eth, wakuv2", - ConnectorConfig: params.ConnectorConfig{Enabled: true}, - HTTPEnabled: true, - HTTPHost: "0.0.0.0", - HTTPPort: 8545, - WSEnabled: false, - WSHost: "127.0.0.1", - WSPort: 8586, + APIModules: "test, eth, wakuv2", + ConnectorConfig: params.ConnectorConfig{Enabled: true}, + HTTPEnabled: true, + HTTPHost: "0.0.0.0", + HTTPPort: 8545, + HTTPVirtualHosts: []string{"status-go"}, + WSEnabled: false, + WSHost: "127.0.0.1", + WSPort: 8586, } apiConfig := &requests.APIConfig{ @@ -27,11 +28,17 @@ func TestOverrideApiConfig(t *testing.T) { HTTPEnabled: false, HTTPHost: "127.0.0.1", HTTPPort: 8080, + HTTPVirtualHosts: []string{"*"}, WSEnabled: true, WSHost: "192.168.0.1", WSPort: 7777, } + return newNodeConfig, apiConfig +} + +func TestOverrideApiConfig(t *testing.T) { + newNodeConfig, apiConfig := setupConfigs() overrideApiConfig(newNodeConfig, apiConfig) require.Equal(t, apiConfig.APIModules, newNodeConfig.APIModules) @@ -39,7 +46,17 @@ func TestOverrideApiConfig(t *testing.T) { require.Equal(t, apiConfig.HTTPEnabled, newNodeConfig.HTTPEnabled) require.Equal(t, apiConfig.HTTPHost, newNodeConfig.HTTPHost) require.Equal(t, apiConfig.HTTPPort, newNodeConfig.HTTPPort) + require.Equal(t, apiConfig.HTTPVirtualHosts, newNodeConfig.HTTPVirtualHosts) require.Equal(t, apiConfig.WSEnabled, newNodeConfig.WSEnabled) require.Equal(t, apiConfig.WSHost, newNodeConfig.WSHost) require.Equal(t, apiConfig.WSPort, newNodeConfig.WSPort) } + +func TestOverrideApiConfigTest(t *testing.T) { + newNodeConfig, apiConfig := setupConfigs() + newNodeConfig.HTTPVirtualHosts = []string{"status-go"} + apiConfig.HTTPVirtualHosts = []string{"*"} + overrideApiConfigTest(newNodeConfig, apiConfig) + + require.Equal(t, apiConfig.HTTPVirtualHosts, newNodeConfig.HTTPVirtualHosts) +} diff --git a/api/defaults.go b/api/defaults.go index 47ce776f4..71a0418fa 100644 --- a/api/defaults.go +++ b/api/defaults.go @@ -43,6 +43,8 @@ var paths = []string{pathWalletRoot, pathEIP1581, pathDefaultChat, pathDefaultWa var DefaultFleet = params.FleetShardsTest +var overrideApiConfig = overrideApiConfigProd + func defaultSettings(keyUID string, address string, derivedAddresses map[string]generator.AccountInfo) (*settings.Settings, error) { chatKeyString := derivedAddresses[pathDefaultChat].PublicKey @@ -215,13 +217,14 @@ func buildWalletConfig(request *requests.WalletSecretsConfig) params.WalletConfi return walletConfig } -func overrideApiConfig(nodeConfig *params.NodeConfig, config *requests.APIConfig) { +func overrideApiConfigProd(nodeConfig *params.NodeConfig, config *requests.APIConfig) { nodeConfig.APIModules = config.APIModules nodeConfig.ConnectorConfig.Enabled = config.ConnectorEnabled nodeConfig.HTTPEnabled = config.HTTPEnabled nodeConfig.HTTPHost = config.HTTPHost nodeConfig.HTTPPort = config.HTTPPort + nodeConfig.HTTPVirtualHosts = config.HTTPVirtualHosts nodeConfig.WSEnabled = config.WSEnabled nodeConfig.WSHost = config.WSHost diff --git a/api/test_helpers.go b/api/test_helpers.go index f11930154..621a0e33c 100644 --- a/api/test_helpers.go +++ b/api/test_helpers.go @@ -10,6 +10,7 @@ import ( "github.com/status-im/status-go/multiaccounts/accounts" "github.com/status-im/status-go/multiaccounts/settings" "github.com/status-im/status-go/params" + "github.com/status-im/status-go/protocol/requests" "github.com/stretchr/testify/require" ) @@ -99,3 +100,13 @@ func setupWalletTest(t *testing.T, password string) (backend *GethStatusBackend, return } + +// Only for tests +func overrideApiConfigTest(nodeConfig *params.NodeConfig, config *requests.APIConfig) { + overrideApiConfigProd(nodeConfig, config) + nodeConfig.HTTPVirtualHosts = config.HTTPVirtualHosts +} + +func OverrideApiConfigTest() { + overrideApiConfig = overrideApiConfigTest +} diff --git a/cmd/statusd/main.go b/cmd/statusd/main.go index 40f2676ea..cb089f7f8 100644 --- a/cmd/statusd/main.go +++ b/cmd/statusd/main.go @@ -215,6 +215,7 @@ func main() { HTTPEnabled: config.HTTPEnabled, HTTPHost: config.HTTPHost, HTTPPort: config.HTTPPort, + HTTPVirtualHosts: config.HTTPVirtualHosts, WSEnabled: config.WSEnabled, WSHost: config.WSHost, WSPort: config.WSPort, @@ -225,6 +226,8 @@ func main() { }, } + api.OverrideApiConfigTest() + _, err := backend.RestoreAccountAndLogin(&request) if err != nil { logger.Error("failed to import account", "error", err) diff --git a/integration-tests/config.json b/integration-tests/config.json index c07cc56fe..2c622d319 100644 --- a/integration-tests/config.json +++ b/integration-tests/config.json @@ -7,6 +7,7 @@ "HTTPEnabled": true, "HTTPHost": "0.0.0.0", "HTTPPort": 3333, + "HTTPVirtualHosts": ["*", "status-go"], "APIModules": "eth,admin,wallet", "WalletConfig": { "Enabled": true diff --git a/protocol/requests/create_account.go b/protocol/requests/create_account.go index 932b4d762..3886fe140 100644 --- a/protocol/requests/create_account.go +++ b/protocol/requests/create_account.go @@ -21,14 +21,15 @@ type ImageCropRectangle struct { } type APIConfig struct { - APIModules string `json:"apiModules"` - ConnectorEnabled bool `json:"connectorEnabled"` - HTTPEnabled bool `json:"httpEnabled"` - HTTPHost string `json:"httpHost"` - HTTPPort int `json:"httpPort"` - WSEnabled bool `json:"wsEnabled"` - WSHost string `json:"wsHost"` - WSPort int `json:"wsPort"` + APIModules string `json:"apiModules"` + ConnectorEnabled bool `json:"connectorEnabled"` + HTTPEnabled bool `json:"httpEnabled"` + HTTPHost string `json:"httpHost"` + HTTPPort int `json:"httpPort"` + HTTPVirtualHosts []string `json:"httpVirtualHosts"` + WSEnabled bool `json:"wsEnabled"` + WSHost string `json:"wsHost"` + WSPort int `json:"wsPort"` } type CreateAccount struct {