[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Review Request 111390: kshorturifilter: inverted condition in home directory handling
From:       "Jonathan Marten" <jjm () keelhaul ! me ! uk>
Date:       2013-07-06 14:51:32
Message-ID: 20130706145132.23971.5333 () vidsolbach ! de
[Download RAW message or body]

> On July 5, 2013, 2:27 p.m., David Faure wrote:
> > Sounds like the unittest is incomplete then, if it didn't catch the error with ~ \
> > or ~user. 
> > 
> > (I don't mean testing the case where the home dir is empty, I only mean the \
> > normal case, which you say was going into an error path).

Having looked at the unittest, it doesn't test for that condition.  It would only be \
triggered in the case of '~user' where the user is valid (and not '~' alone because \
that is a separate code path).  The unittest only checks for '~foobar', a nonexistent \
user, so user.isValid() is false and the second condition would never be tried.

The case that does exercise this code would be '~user' where the user does exist;  \
for example testing for '~bin'.  Running the test with the unmodified code does give \
a test fail:

QDEBUG : KUriFilterTest::localFiles() qttest(11024)/kurifilter (plugins) \
KShortUriFilter::filterUri: "~bin" QDEBUG : KUriFilterTest::localFiles() \
qttest(11024) filter: *** Result: Encountered error => ' "/bin" ' QDEBUG : \
KUriFilterTest::localFiles() qttest(11024) filter: Reason: "<html><b>bin</b> does not \
                have a home folder.</html>"
QSYSTEM: KUriFilterTest::localFiles() qttest(11024): ~bin Got URI type ERROR expected \
LOCAL_DIR  FAIL!  : KUriFilterTest::localFiles() Compared strings are not the same
   Actual (s_uritypes[filterData->uriType()]): ERROR
   Expected (s_uritypes[expectedUriType]): LOCAL_DIR
   Loc: [/ws/trunk/kdebase/kderuntime/kurifilter-plugins/tests/kurifiltertest.cpp(109)]


but with the modified code the test passes.

Should I commit an additional test of

    filter( "~bin", 0, KUriFilterData::LocalDir, QStringList( "kshorturifilter" ) );

to make the coverage complete?


- Jonathan


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/111390/#review35635
-----------------------------------------------------------


On July 4, 2013, 6:32 p.m., Jonathan Marten wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/111390/
> -----------------------------------------------------------
> 
> (Updated July 4, 2013, 6:32 p.m.)
> 
> 
> Review request for KDE Runtime.
> 
> 
> Description
> -------
> 
> While investigating URI filtering/validation elsewhere I spotted some odd logic \
> here.  The original line in question seems to be saying: 
> if (user is valid && user's home directory is empty)
> {
> // replace from '~' onwards with home directory
> }
> else
> {
> // generate an error
> }
> 
> The second condition, though, is surely wrong.  It should say:
> 
> if (user is valid && user's home directory is NOT empty)
> ...
> 
> 
> Diffs
> -----
> 
> kurifilter-plugins/shorturi/kshorturifilter.cpp d27b018 
> 
> Diff: http://git.reviewboard.kde.org/r/111390/diff/
> 
> 
> Testing
> -------
> 
> Build kderumtime with this change.  Checked correct results for '~' and '~user', \
> where the user both exists and does not, in konqueror and krunner.  Ran the \
> kurifiltertest with all passes. 
> 
> Thanks,
> 
> Jonathan Marten
> 
> 


[Attachment #3 (text/html)]

<html>
 <body>
  <div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
   <table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 \
solid;">  <tr>
     <td>
      This is an automatically generated e-mail. To reply, visit:
      <a href="http://git.reviewboard.kde.org/r/111390/">http://git.reviewboard.kde.org/r/111390/</a>
  </td>
    </tr>
   </table>
   <br />





<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;">  <p style="margin-top: 0;">On July 5th, 2013, 2:27 p.m. UTC, <b>David \
Faure</b> wrote:</p>  <blockquote style="margin-left: 1em; border-left: 2px solid \
#d0d0d0; padding-left: 10px;">  <pre style="white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">Sounds like the unittest is incomplete then, if it didn&#39;t catch the \
error with ~ or ~user.


(I don&#39;t mean testing the case where the home dir is empty, I only mean the \
normal case, which you say was going into an error path).</pre>  </blockquote>







</blockquote>

<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Having looked at the \
unittest, it doesn&#39;t test for that condition.  It would only be triggered in the \
case of &#39;~user&#39; where the user is valid (and not &#39;~&#39; alone because \
that is a separate code path).  The unittest only checks for &#39;~foobar&#39;, a \
nonexistent user, so user.isValid() is false and the second condition would never be \
tried.

The case that does exercise this code would be &#39;~user&#39; where the user does \
exist;  for example testing for &#39;~bin&#39;.  Running the test with the unmodified \
code does give a test fail:

QDEBUG : KUriFilterTest::localFiles() qttest(11024)/kurifilter (plugins) \
KShortUriFilter::filterUri: &quot;~bin&quot; QDEBUG : KUriFilterTest::localFiles() \
qttest(11024) filter: *** Result: Encountered error =&gt; &#39; &quot;/bin&quot; \
&#39; QDEBUG : KUriFilterTest::localFiles() qttest(11024) filter: Reason: \
&quot;&lt;html&gt;&lt;b&gt;bin&lt;/b&gt; does not have a home \
                folder.&lt;/html&gt;&quot;
QSYSTEM: KUriFilterTest::localFiles() qttest(11024): ~bin Got URI type ERROR expected \
LOCAL_DIR  FAIL!  : KUriFilterTest::localFiles() Compared strings are not the same
   Actual (s_uritypes[filterData-&gt;uriType()]): ERROR
   Expected (s_uritypes[expectedUriType]): LOCAL_DIR
   Loc: [/ws/trunk/kdebase/kderuntime/kurifilter-plugins/tests/kurifiltertest.cpp(109)]


but with the modified code the test passes.

Should I commit an additional test of

    filter( &quot;~bin&quot;, 0, KUriFilterData::LocalDir, QStringList( \
&quot;kshorturifilter&quot; ) );

to make the coverage complete?
</pre>
<br />










<p>- Jonathan</p>


<br />
<p>On July 4th, 2013, 6:32 p.m. UTC, Jonathan Marten wrote:</p>








<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" \
style="background-image: \
url('http://git.reviewboard.kde.org/static/rb/images/review_request_box_top_bg.ab6f3b1072c9.png'); \
background-position: left top; background-repeat: repeat-x; border: 1px black \
solid;">  <tr>
  <td>

<div>Review request for KDE Runtime.</div>
<div>By Jonathan Marten.</div>


<p style="color: grey;"><i>Updated July 4, 2013, 6:32 p.m.</i></p>






<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
 <table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" \
style="border: 1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">While investigating URI filtering/validation elsewhere I spotted some \
odd logic here.  The original line in question seems to be saying:

if (user is valid &amp;&amp; user&#39;s home directory is empty)
{
  // replace from &#39;~&#39; onwards with home directory
}
else
{
  // generate an error
}

The second condition, though, is surely wrong.  It should say:

if (user is valid &amp;&amp; user&#39;s home directory is NOT empty)
...
</pre>
  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: \
1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">Build kderumtime with this change.  Checked correct results for \
&#39;~&#39; and &#39;~user&#39;, where the user both exists and does not, in \
konqueror and krunner.  Ran the kurifiltertest with all passes. </pre>
  </td>
 </tr>
</table>




<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">

 <li>kurifilter-plugins/shorturi/kshorturifilter.cpp <span style="color: \
grey">(d27b018)</span></li>

</ul>

<p><a href="http://git.reviewboard.kde.org/r/111390/diff/" style="margin-left: \
3em;">View Diff</a></p>







  </td>
 </tr>
</table>








  </div>
 </body>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic