Re: [PATCH v3] test: replace notmuch_passwd_sanitize() with _libconfig_sanitize()

Subject: Re: [PATCH v3] test: replace notmuch_passwd_sanitize() with _libconfig_sanitize()

Date: Wed, 19 May 2021 20:34:24 +0300

To: Felipe Contreras

Cc: notmuch@notmuchmail.org

From: Tomi Ollila


On Wed, May 19 2021, Tomi Ollila wrote:

> On Wed, May 19 2021, Felipe Contreras wrote:
>
>>
>> Why not use a heredoc?
>>
>>   python <<-EOF
>>   ..
>>   EOF
>
> tldr: I'll post change to use heredoc.

... which did not work ...

> Probably my bias against heredoc's when there are alternatives
> -- although this is much more tolerable than cat <<EOF ... EOF
> to write stuff to stdout ;)
>
> Also, I did not recall it is this simple to read python code
> from stdin to be executed (right, that loses stdin for user
> input -- I was once bitten by that so that contributes to 
> my bias).

Haha, as we do _libconfig_sanitize < OUTPUT > OUTPUT.clean
reading python script from stdin don't work (perl has __DATA__ ;).
(bitten again, I did and tested the change... :D).

I'd rather keep the same "filter" style here as in everywhere
else in our test scripts, and chr(39) instead of exiting out
from the single quoted string temporarily in order to add
that/those single quote(s) to the argument for python3 -c ...

So [PATCH v3] in id:20210518055443.21964-1-tomi.ollila@iki.fi
is my fix proposal.

Tomi

>
> Here the ability to use "'" (for clarity) is compelling reason
> to use heredoc.
>
> (alternatives would have been:
>
>  * l.replace("'\''" + name ...
>
>  * l.replace("'"'"'" + name ... ;D
>
>  * use other delimiter than ' (but not unicode quotes >;)
> )
>
> While testing this option I looked (once again) how dash and
> bash do heredocs (in linux) (just to update my knowledge):
>
> dash creates pipe and dup2's fd[0] to 0 
>      (that makes stdin not seekable)
>
> bash clones subprocess; in subprocess it creates temporary file,
>      writes data there, closes it, opens it for reading, 
>      unlinks it from fs (could be problematic on windows), 
>      dup2()'s it to stdin, closes the dupped fd and finally
>      execve's python
>
> zsh works like bash (i.e. these 2 provide seekable stdin)
>
> $ (strace -f -ofile zsh heredoc-test.sh)
>
> Tomi
>
>>
>>> +pw = pwd.getpwuid(os.getuid())
>>> +user = pw.pw_name
>>> +name = pw.pw_gecos.partition(",")[0]
>>> +fqdn = socket.getaddrinfo(socket.gethostname(), 0, 0,
>>> +                          socket.SOCK_STREAM, 0, socket.AI_CANONNAME)[0][3]
>>> +for l in sys.stdin:
>>> +    if l[:3] == "8: ":
>>> +        l = l.replace(user, "USERNAME", 1).replace("@" + fqdn, "@FQDN", 1)
>>> +        l = l.replace(".(none)", "", 1).replace(".localdomain", "", 1)
>>> +    elif l[:3] == "a: ":
>>> +        sq = chr(39) # single quote
>>> +        l = l.replace(sq + name, sq + "USER_FULL_NAME", 1)
>>
>> Then we can simply do:
>>
>> l.replace("'" + name, "'USER_FULL_NAME", 1)
>>
>> The rest looks fine to me.
>>
>> -- 
>> Felipe Contreras
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: