<div dir="ltr"><div>Hi,<br><br></div>Modification are made and the patch is attached with the mail. The required tests for getpwuid operations are passing. Kindly review the patch.<br><br><br><br><div><div><div><div class="gmail_extra">
<br><div class="gmail_quote">On 25 February 2014 20:40, Jakub Hrozek <span dir="ltr">&lt;<a href="mailto:jhrozek@redhat.com" target="_blank">jhrozek@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Sat, Feb 15, 2014 at 01:04:36AM +0545, Pallavi Jha wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; Attached is a  patch with the additional test functions for getpwuid*<br>
&gt; functions. I think I did not get the flow of the data in program properly.<br>
&gt; That is why getting similar errors.<br>
&gt;<br>
&gt; Please have a look into the patch and let me know how to improve upon it.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Thanks!<br>
&gt; Pallavi<br>
<br>
</div></div>Hi,<br>
<br>
this test is mostly good after I did some local modifications. See a<br>
couple of comments inline.<br>
<br>
&gt; From 5341e1331d984f48ee28118dba05d11dd4f068c4 Mon Sep 17 00:00:00 2001<br>
&gt; From: Pallavi Jha &lt;<a href="mailto:pallavikumarijha@gmail.com">pallavikumarijha@gmail.com</a>&gt;<br>
&gt; Date: Mon, 27 Jan 2014 19:31:06 +0545<br>
&gt; Subject: [PATCH] cmocka-unit-test-for-functions-getpwuid*-added<br>
<br>
[snip]<br>
<br>
&gt; +static void mock_input_id(uint8_t *id)<br>
&gt; +{<br>
&gt; +    will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);<br>
&gt; +    will_return(__wrap_sss_packet_get_body, id);<br>
&gt; +}<br>
&gt; +<br>
<br>
I had to change this function, what the responder expects is a body and<br>
body length which was previously only strlen. Now with this test we want<br>
to pass an uint32_t to SSSD, so we need to have a way to set the blen to<br>
sizeof(uint32_t). See the attached patch that applies on top of yours.<br>
<br>
&gt;  static void mock_fill_user(void)<br>
&gt;  {<br>
&gt;      /* One packet for the entry and one for num entries */<br>
&gt; @@ -587,6 +606,343 @@ void test_nss_getpwnam_fqdn_fancy(void **state)<br>
&gt;      assert_int_equal(ret, EOK);<br>
&gt;  }<br>
&gt;<br>
&gt; +/* Check getting cached and valid id from cache. Account callback will<br>
&gt; + * not be called and test_nss_getpwuid_check will make sure the id is<br>
&gt; + * the same as the test entered before starting<br>
&gt; + */<br>
&gt; +static int test_nss_getpwuid_check(uint32_t status, uint8_t *body, size_t blen)<br>
&gt; +{<br>
&gt; +    struct passwd pwd;<br>
&gt; +    errno_t ret;<br>
&gt; +<br>
&gt; +    assert_int_equal(status, EOK);<br>
&gt; +<br>
&gt; +    ret = parse_user_packet(body, blen, &amp;pwd);<br>
&gt; +    assert_int_equal(ret, EOK);<br>
&gt; +<br>
&gt; +    assert_int_equal(pwd.pw_uid, 101);<br>
&gt; +    assert_int_equal(pwd.pw_gid, 401);<br>
&gt; +    assert_string_equal(pwd.pw_name, &quot;testuser1&quot;);<br>
&gt; +    assert_string_equal(pwd.pw_shell, &quot;/bin/sh&quot;);<br>
&gt; +    assert_string_equal(pwd.pw_passwd, &quot;*&quot;);<br>
&gt; +    return EOK;<br>
&gt; +}<br>
&gt; +<br>
&gt; +void test_nss_getpwuid(void **state)<br>
&gt; +{<br>
&gt; +    errno_t ret;<br>
&gt; +<br>
&gt; +    /* Prime the cache with a valid user */<br>
&gt; +    ret = sysdb_add_user(nss_test_ctx-&gt;tctx-&gt;dom,<br>
&gt; +                         &quot;testuser1&quot;, 101, 401, &quot;test user1&quot;,<br>
&gt; +                         &quot;/home/testuser1&quot;, &quot;/bin/sh&quot;, NULL,<br>
&gt; +                         NULL, 300, 0);<br>
&gt; +    assert_int_equal(ret, EOK);<br>
&gt; +<br>
&gt; +    uint8_t id = 101;<br>
<br>
IDs in Linux are larger, typically uid_t is used, but inside SSSD we use<br>
uint32_t.<br>
<br>
&gt; +    mock_input_id(&amp;id);<br>
&gt; +    will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID);<br>
&gt; +    mock_fill_user();<br>
&gt; +<br>
&gt; +    /* Query for that id, call a callback when command finishes */<br>
&gt; +    set_cmd_cb(test_nss_getpwuid_check);<br>
&gt; +    ret = sss_cmd_execute(nss_test_ctx-&gt;cctx, SSS_NSS_GETPWUID,<br>
&gt; +                          nss_test_ctx-&gt;nss_cmds);<br>
&gt; +    assert_int_equal(ret, EOK);<br>
&gt; +<br>
&gt; +    /* Wait until the test finishes with EOK */<br>
&gt; +    ret = test_ev_loop(nss_test_ctx-&gt;tctx);<br>
&gt; +    assert_int_equal(ret, EOK);<br>
&gt; +}<br>
&gt; +<br>
<br>
The other tests were mostly good, so I&#39;m going to omit those.<br>
<br>
&gt; +static int test_nss_getpwuid_check_fqdn(uint32_t status,<br>
&gt; +                                        uint8_t *body, size_t blen)<br>
<br>
Unlike get-&lt;something&gt;-by-name, get-by-id doesn&#39;t support fully<br>
qualified lookups. So you can just remove the getpwuid_fqdn tests.<br>
<br>
&gt; +{<br>
&gt; +    struct passwd pwd;<br>
&gt; +    errno_t ret;<br>
&gt; +<br>
&gt; +    assert_int_equal(status, EOK);<br>
&gt; +<br>
&gt; +    nss_test_ctx-&gt;cctx-&gt;rctx-&gt;domains[0].fqnames = false;<br>
&gt; +<br>
&gt; +    ret = parse_user_packet(body, blen, &amp;pwd);<br>
&gt; +    assert_int_equal(ret, EOK);<br>
&gt; +<br>
&gt; +    assert_int_equal(pwd.pw_uid, 301);<br>
&gt; +    assert_int_equal(pwd.pw_gid, 755);<br>
&gt; +    assert_string_equal(pwd.pw_name, &quot;exampleuser_fqdn@&quot;TEST_DOM_NAME);<br>
&gt; +    assert_string_equal(pwd.pw_shell, &quot;/bin/sh&quot;);<br>
&gt; +    return EOK;<br>
&gt; +}<br>
&gt; +<br>
&gt; +void test_nss_getpwuid_fqdn(void **state)<br>
&gt; +{<br>
&gt; +    errno_t ret;<br>
&gt; +<br>
&gt; +    /* Prime the cache with a valid user */<br>
&gt; +    ret = sysdb_add_user(nss_test_ctx-&gt;tctx-&gt;dom,<br>
&gt; +                         &quot;exampleuser_fqdn&quot;, 301, 755, &quot;example user&quot;,<br>
&gt; +                         &quot;/home/exampleuser&quot;, &quot;/bin/sh&quot;, NULL,<br>
&gt; +                         NULL, 300, 0);<br>
&gt; +    assert_int_equal(ret, EOK);<br>
&gt; +<br>
&gt; +    uint8_t id = 301;<br>
<br>
btw 301 doesn&#39;t fit uinto uint8_t. But that&#39;s not really important<br>
anymore since we&#39;re changing the type to uint32_t.<br>
<br>
Good work in overall! Please check out the attached patch and squash it<br>
in if you agree. With the patch, all tests except the fqdn ones pass,<br>
but the fqdn test should be removed anyway.<br>
</blockquote></div><br></div></div></div></div></div>