mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-02 13:43:11 +00:00
paths are already sanitized, removing allowed
This commit is contained in:
parent
309ac94f21
commit
29577b6dd7
@ -29,13 +29,6 @@ const
|
||||
"/home",
|
||||
"/Users"]
|
||||
|
||||
Allowed* = {
|
||||
'a'..'z',
|
||||
'A'..'Z',
|
||||
'0'..'9',
|
||||
DirSep, AltSep,
|
||||
'_', '-', '.'}
|
||||
|
||||
type
|
||||
FSDatastore* = ref object of Datastore
|
||||
root*: string
|
||||
@ -59,16 +52,6 @@ template path*(self: FSDatastore, key: Key): string =
|
||||
template checkProtected*(path: string): bool =
|
||||
path in ProtectedPaths
|
||||
|
||||
template allowed*(path: string): bool =
|
||||
var notfound = true
|
||||
for s in path:
|
||||
if s.char notin Allowed:
|
||||
echo "INVALID CHAR ", s
|
||||
notfound = false
|
||||
break
|
||||
|
||||
notfound
|
||||
|
||||
template validDepth*(self: FSDatastore, key: Key): bool =
|
||||
key.len <= self.depth
|
||||
|
||||
@ -80,9 +63,6 @@ method contains*(self: FSDatastore, key: Key): Future[?!bool] {.async.} =
|
||||
let
|
||||
path = self.path(key)
|
||||
|
||||
if not path.allowed:
|
||||
return failure "Path is contains invalid characters!"
|
||||
|
||||
if checkProtected(path):
|
||||
return failure "Path is protected!"
|
||||
|
||||
@ -96,9 +76,6 @@ method delete*(self: FSDatastore, key: Key): Future[?!void] {.async.} =
|
||||
let
|
||||
path = self.path(key)
|
||||
|
||||
if not path.allowed:
|
||||
return failure "Path is contains invalid characters!"
|
||||
|
||||
if checkProtected(path):
|
||||
return failure "Path is protected!"
|
||||
|
||||
@ -128,9 +105,6 @@ method get*(self: FSDatastore, key: Key): Future[?!seq[byte]] {.async.} =
|
||||
let
|
||||
path = self.path(key)
|
||||
|
||||
if not path.allowed:
|
||||
return failure "Path is contains invalid characters!"
|
||||
|
||||
if checkProtected(path):
|
||||
return failure "Path is protected!"
|
||||
|
||||
@ -177,9 +151,6 @@ method put*(
|
||||
let
|
||||
path = self.path(key)
|
||||
|
||||
if not path.allowed:
|
||||
return failure "Path is contains invalid characters!"
|
||||
|
||||
if checkProtected(path):
|
||||
return failure "Path is protected!"
|
||||
|
||||
|
||||
@ -79,35 +79,6 @@ suite "Test Misc FSDatastore":
|
||||
(await fs.delete(key)).isErr
|
||||
(await fs.contains(key)).isErr
|
||||
|
||||
test "Test allowed()":
|
||||
let
|
||||
chars = [
|
||||
"/a*", "/a/b*", "/a/b$", "/a/b()",
|
||||
"/a/b+", "/a/b$", "/d%", "/A/b@",
|
||||
"/A!", "/b#/##"]
|
||||
|
||||
for c in chars:
|
||||
check not c.allowed
|
||||
|
||||
test "Test valid key (path) names":
|
||||
let
|
||||
fs = FSDatastore.new(root = basePathAbs).tryGet()
|
||||
bytes = "some bytes".toBytes
|
||||
chars =
|
||||
["/a*", "/a/b*", "/a/b$", "/a/b()",
|
||||
"/a/b+", "/a/b$", "/d%", "/A/b@",
|
||||
"/A!", "/b#/##"]
|
||||
|
||||
for c in chars:
|
||||
let
|
||||
key = Key.init(c).tryGet()
|
||||
|
||||
check:
|
||||
(await fs.put(key, bytes)).isErr
|
||||
(await fs.get(key)).isErr
|
||||
(await fs.delete(key)).isErr
|
||||
(await fs.contains(key)).isErr
|
||||
|
||||
test "Test validDepth()":
|
||||
let
|
||||
fs = FSDatastore.new(root = "/", depth = 3).tryGet()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user