diff --git a/apps/simplex-store-service/src/StoreService/Config.hs b/apps/simplex-store-service/src/StoreService/Config.hs index 11abb1587e..e702e7038e 100644 --- a/apps/simplex-store-service/src/StoreService/Config.hs +++ b/apps/simplex-store-service/src/StoreService/Config.hs @@ -31,7 +31,7 @@ import qualified Data.ByteArray as BA import Data.ByteArray.Encoding (Base (Base16), convertFromBase) import qualified Data.ByteString.Char8 as B import Data.Ini (Ini, iniGlobals, iniParser, keys, lookupValue, sections) -import Data.Maybe (fromMaybe) +import Data.Maybe (fromMaybe, isJust, isNothing) import Data.Text (Text) import qualified Data.Text as T import Data.Text.Encoding (encodeUtf8) @@ -255,6 +255,8 @@ parseConfig ini = do let lNamesStaticDir = T.unpack <$> present "listener" "names_static_dir" lNamesExportDir = T.unpack <$> present "listener" "names_export_dir" lNamesHosts = maybe [] (filter (not . T.null) . map (T.toLower . T.strip) . T.splitOn ",") (present "listener" "names_hosts") + when (isNothing lNamesStaticDir && (not (null lNamesHosts) || isJust lNamesExportDir)) $ + Left "listener.names_static_dir is required with names_hosts or names_export_dir" btc <- btcpaySection str <- stripeSection iss <- issuerSection diff --git a/tests/Bots/StoreService/ConfigTests.hs b/tests/Bots/StoreService/ConfigTests.hs index 303c3a171a..af36e29d3d 100644 --- a/tests/Bots/StoreService/ConfigTests.hs +++ b/tests/Bots/StoreService/ConfigTests.hs @@ -4,6 +4,7 @@ module Bots.StoreService.ConfigTests where import StoreService.Config +import Control.Monad (forM_) import qualified Data.ByteArray as BA import qualified Data.ByteString.Char8 as B import Data.Either (isLeft) @@ -420,6 +421,7 @@ namesConfigTests = describe "StoreService names: config" $ do it "reads [names] and [chain], applying every documented default" testNamesDefaults it "reads every [names] and [chain] setting written out" testNamesWrittenOut it "reads the names keys of [listener]" testNamesListenerKeys + it "refuses names_hosts or names_export_dir without names_static_dir" testNamesSiteNeedsItsBuild it "leaves the names side off when [names] is absent" testNamesAbsent it "refuses [names] without [chain], and [chain] without [names]" testNamesNeedsChain it "refuses years below 2" testNamesYearsBelowTwo @@ -524,6 +526,13 @@ testNamesListenerKeys = do let ListenerConfig {lNamesStaticDir = noDir, lNamesExportDir = noExport, lNamesHosts = noHosts} = listener plain (noDir, noExport, noHosts) `shouldBe` (Nothing, Nothing, []) +testNamesSiteNeedsItsBuild :: IO () +testNamesSiteNeedsItsBuild = + forM_ ["names_hosts = simplex.domains", "names_export_dir = /srv/names-out"] $ \key -> do + let withKey = T.replace "static_dir = /srv/badges\n" ("static_dir = /srv/badges\n" <> key <> "\n") fullIni + r <- parseIni withKey + either id (const "parsed") r `shouldBe` "listener.names_static_dir is required with names_hosts or names_export_dir" + testNamesAbsent :: IO () testNamesAbsent = do Right cfg <- parseIni fullIni