On Thu, Dec 6, 2018 at 10:48 AM Rob Landley <[email protected]> wrote:
>
> On 12/6/18 10:55 AM, enh wrote:
> > it occurred to me overnight that the passwd code allows '/'. plus, as
> > i've said, it seems to be slightly wrong. so i've just sent a
> > replacement for my second patch (to be applied on top of the first
> > patch) that just does the simplest xgetrandom + convert to valid
> > character loop.
> >
> > can we at least get the first patch in, since mktemp is pretty broken
> > right now (_except_ for -u, which was all the old tests exercised)?
>
> Can you send me just a tests/mktemp.test patch to demonstrate the failures? 
> I'll
> try to fix it this evening. (Too many changes at once, I need to know what
> success looks like...)

you could just apply the two patches... that way you'll have the tests
_and_ they'll pass. (the _real_ question is whether we're still
missing important tests, since we were only testing -u until now. plus
testing "the Xs get replaced with random data" is inherently hard to
test.)

i've attached "just the tests" to this mail.

> Thanks,
>
> Rob
From 4eb17f7d48f5a2b408d3b050fa27700925902288 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Thu, 6 Dec 2018 11:06:55 -0800
Subject: [PATCH] mktemp: just the missing tests.

---
 tests/mktemp.test | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/tests/mktemp.test b/tests/mktemp.test
index ee7702dc..0c235469 100755
--- a/tests/mktemp.test
+++ b/tests/mktemp.test
@@ -6,11 +6,20 @@
 
 # mktemp by default should use tmp.XXXXXXXXXX as the template,
 # and $TMPDIR as the directory.
-testing "default" "TMPDIR=/t mktemp -u | grep -q '^/t/tmp\...........$' && echo yes" "yes\n" "" ""
+testing "default" "TMPDIR=. mktemp | grep -q '^./tmp\...........$' && echo yes" "yes\n" "" ""
+
+# Test that -d creates a directory and the default is a file.
+testing "dir" "test -d `TMPDIR=. mktemp -d` && echo yes" "yes\n" "" ""
+testing "file" "test -f `TMPDIR=. mktemp` && echo yes" "yes\n" "" ""
 
 # mktemp with a template should *not* use $TMPDIR.
 testing "TEMPLATE" "TMPDIR=/t mktemp -u hello.XXXXXXXX | grep -q '^hello\.........$' && echo yes" "yes\n" "" ""
 
+# mktemp with a template that includes a '/' should ignore $TMPDIR
+testing "/ TEMPLATE" "TMPDIR=/t mktemp -u /x/hello.XXXXXXXX | grep -q '^/x/hello\.........$' && echo yes" "yes\n" "" ""
+# ...and setting DIR is an error.
+testing "/ TEMPLATE -p DIR" "TMPDIR=/t mktemp -p DIR -u /x/hello.XXXXXXXX || echo error" "error\n" "" ""
+
 # mktemp with -t and a template should use $TMPDIR.
 testing "-t TEMPLATE" "TMPDIR=/t mktemp -u -t hello.XXXXXXXX | grep -q '^/t/hello\.........$' && echo yes" "yes\n" "" ""
 
@@ -28,3 +37,9 @@ testing "-p DIR -t TEMPLATE but no TMPDIR" "TMPDIR= mktemp -u -p DIR -t hello.XX
 
 # mktemp -u doesn't need to be able to write to the directory.
 testing "-u" "mktemp -u -p /proc | grep -q '^/proc/tmp\...........$' && echo yes" "yes\n" "" ""
+
+# mktemp needs at least XX in the template.
+testing "bad template" "mktemp -u helloX || echo error" "error\n" "" ""
+
+# mktemp -q shouldn't print the path.
+testing "-q" "mktemp -p /proc -q || echo only-failure" "only-failure\n" "" ""
-- 
2.20.0.rc1.387.gf8505762e3-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to