Re: [PATCH 1/3] tests: Add mock for virRandomBytes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 18, 2016 at 19:52:30 -0400, John Ferlan wrote:
> Create a mock for virRandomBytes to generate a not so random value that
> can be used by the tests to ensure the generation of an encrypted secret
> by masterKey and random initialization vector can produce an expected
> result.  The "random number" generated is based upon the size of the
> expected stream of bytes being returned where each byte in the result
> gets the index of the array - hence a 4 byte array returns 0x00010203.
> 
> Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
> ---
>  tests/qemuxml2argvmock.c | 31 ++++++++++++++++++++++++++++++-
>  1 file changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c
> index 1616eed..dade748 100644
> --- a/tests/qemuxml2argvmock.c
> +++ b/tests/qemuxml2argvmock.c

[...]

> @@ -145,3 +152,25 @@ virCommandPassFD(virCommandPtr cmd ATTRIBUTE_UNUSED,
>  {
>      /* nada */
>  }
> +
> +int
> +virRandomBytes(unsigned char *buf,
> +               size_t buflen)
> +{
> +    size_t i;
> +
> +    for (i = 0; i < buflen; i++)
> +        buf[i] = i;
> +
> +    return 0;
> +}
> +
> +#ifdef WITH_GNUTLS
> +int
> +gnutls_rnd(gnutls_rnd_level_t level ATTRIBUTE_UNUSED,
> +           void *data,
> +           size_t len)
> +{
> +    return virRandomBytes(data, len);
> +#endif

As I've pointed out last time, this won't compile without gnutls.

> +}

Peter

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]