mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-03 00:12:55 +00:00
store: refuse names site keys without its build
This commit is contained in:
1 parent
69ac68090c
commit
ccfcdac20f
2 files changed
+12
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user