~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/tests/libsvn_subr/stream-test.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
      while (len == TEST_BUF_SIZE)
74
74
        {
75
75
          /* Read a chunk ... */
76
 
          SVN_ERR(svn_stream_read(stream, buffer, &len));
 
76
          SVN_ERR(svn_stream_read_full(stream, buffer, &len));
77
77
 
78
78
          /* ... and append the chunk to the stringbuf. */
79
79
          svn_stringbuf_appendbytes(outbuf, buffer, len);
206
206
      while (len >= TEST_BUF_SIZE)
207
207
        {
208
208
          len = TEST_BUF_SIZE;
209
 
          SVN_ERR(svn_stream_read(stream, buf, &len));
 
209
          SVN_ERR(svn_stream_read_full(stream, buf, &len));
210
210
          if (len > 0)
211
211
            svn_stringbuf_appendbytes(inbuf, buf, len);
212
212
        }
332
332
  stringbuf = svn_stringbuf_create("OneTwo", pool);
333
333
  stream = svn_stream_from_stringbuf(stringbuf, pool);
334
334
  len = 3;
335
 
  SVN_ERR(svn_stream_read(stream, buf, &len));
 
335
  SVN_ERR(svn_stream_read_full(stream, buf, &len));
336
336
  buf[3] = '\0';
337
337
  SVN_TEST_STRING_ASSERT(buf, "One");
338
338
  SVN_ERR(svn_stream_mark(stream, &mark, pool));
339
339
  len = 3;
340
 
  SVN_ERR(svn_stream_read(stream, buf, &len));
 
340
  SVN_ERR(svn_stream_read_full(stream, buf, &len));
341
341
  buf[3] = '\0';
342
342
  SVN_TEST_STRING_ASSERT(buf, "Two");
343
343
  SVN_ERR(svn_stream_seek(stream, mark));
344
344
  len = 3;
345
 
  SVN_ERR(svn_stream_read(stream, buf, &len));
 
345
  SVN_ERR(svn_stream_read_full(stream, buf, &len));
346
346
  buf[3] = '\0';
347
347
  SVN_TEST_STRING_ASSERT(buf, "Two");
348
348
 
351
351
  SVN_ERR(svn_stream_skip(stream, 2));
352
352
  /* The remaining line should be empty */
353
353
  len = 3;
354
 
  SVN_ERR(svn_stream_read(stream, buf, &len));
 
354
  SVN_ERR(svn_stream_read_full(stream, buf, &len));
355
355
  buf[len] = '\0';
356
356
  SVN_TEST_ASSERT(len == 1);
357
357
  SVN_TEST_STRING_ASSERT(buf, "o");
381
381
                                                  FALSE, keywords, TRUE, pool);
382
382
  /* Seek from outside of keyword to inside of keyword. */
383
383
  len = 25;
384
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
384
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
385
385
  SVN_TEST_ASSERT(len == 25);
386
386
  buf[25] = '\0';
387
387
  SVN_TEST_STRING_ASSERT(buf, "One$MyKeyword: my keyword");
389
389
  SVN_ERR(svn_stream_reset(translated_stream));
390
390
  SVN_ERR(svn_stream_seek(translated_stream, mark));
391
391
  len = 4;
392
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
392
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
393
393
  SVN_TEST_ASSERT(len == 4);
394
394
  buf[4] = '\0';
395
395
  SVN_TEST_STRING_ASSERT(buf, " was");
397
397
  SVN_ERR(svn_stream_seek(translated_stream, mark));
398
398
  SVN_ERR(svn_stream_skip(translated_stream, 2));
399
399
  len = 2;
400
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
400
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
401
401
  SVN_TEST_ASSERT(len == 2);
402
402
  buf[len] = '\0';
403
403
  SVN_TEST_STRING_ASSERT(buf, "as");
405
405
  /* Seek from inside of keyword to inside of keyword. */
406
406
  SVN_ERR(svn_stream_mark(translated_stream, &mark, pool));
407
407
  len = 9;
408
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
408
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
409
409
  SVN_TEST_ASSERT(len == 9);
410
410
  buf[9] = '\0';
411
411
  SVN_TEST_STRING_ASSERT(buf, " expanded");
412
412
  SVN_ERR(svn_stream_seek(translated_stream, mark));
413
413
  len = 9;
414
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
414
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
415
415
  SVN_TEST_ASSERT(len == 9);
416
416
  buf[9] = '\0';
417
417
  SVN_TEST_STRING_ASSERT(buf, " expanded");
419
419
  SVN_ERR(svn_stream_seek(translated_stream, mark));
420
420
  SVN_ERR(svn_stream_skip(translated_stream, 6));
421
421
  len = 3;
422
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
422
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
423
423
  SVN_TEST_ASSERT(len == 3);
424
424
  buf[len] = '\0';
425
425
  SVN_TEST_STRING_ASSERT(buf, "ded");
427
427
  /* Seek from inside of keyword to outside of keyword. */
428
428
  SVN_ERR(svn_stream_mark(translated_stream, &mark, pool));
429
429
  len = 4;
430
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
430
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
431
431
  SVN_TEST_ASSERT(len == 4);
432
432
  buf[4] = '\0';
433
433
  SVN_TEST_STRING_ASSERT(buf, " $Tw");
434
434
  SVN_ERR(svn_stream_seek(translated_stream, mark));
435
435
  len = 4;
436
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
436
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
437
437
  SVN_TEST_ASSERT(len == 4);
438
438
  buf[4] = '\0';
439
439
  SVN_TEST_STRING_ASSERT(buf, " $Tw");
441
441
  SVN_ERR(svn_stream_seek(translated_stream, mark));
442
442
  SVN_ERR(svn_stream_skip(translated_stream, 2));
443
443
  len = 2;
444
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
444
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
445
445
  SVN_TEST_ASSERT(len == 2);
446
446
  buf[len] = '\0';
447
447
  SVN_TEST_STRING_ASSERT(buf, "Tw");
449
449
  /* Seek from outside of keyword to outside of keyword. */
450
450
  SVN_ERR(svn_stream_mark(translated_stream, &mark, pool));
451
451
  len = 1;
452
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
452
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
453
453
  SVN_TEST_ASSERT(len == 1);
454
454
  buf[1] = '\0';
455
455
  SVN_TEST_STRING_ASSERT(buf, "o");
456
456
  SVN_ERR(svn_stream_seek(translated_stream, mark));
457
457
  len = 1;
458
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
458
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
459
459
  SVN_TEST_ASSERT(len == 1);
460
460
  buf[1] = '\0';
461
461
  SVN_TEST_STRING_ASSERT(buf, "o");
463
463
  SVN_ERR(svn_stream_seek(translated_stream, mark));
464
464
  SVN_ERR(svn_stream_skip(translated_stream, 2));
465
465
  len = 1;
466
 
  SVN_ERR(svn_stream_read(translated_stream, buf, &len));
 
466
  SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
467
467
  SVN_TEST_ASSERT(len == 0);
468
468
  buf[len] = '\0';
469
469
  SVN_TEST_STRING_ASSERT(buf, "");
524
524
                                 pool, pool));
525
525
  stream = svn_stream_compressed(empty_file_stream, pool);
526
526
  len = sizeof(buf);
527
 
  SVN_ERR(svn_stream_read(stream, buf, &len));
 
527
  SVN_ERR(svn_stream_read_full(stream, buf, &len));
528
528
  if (len > 0)
529
529
    return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
530
530
                            "Got unexpected result.");
727
727
  return SVN_NO_ERROR;
728
728
}
729
729
 
 
730
static svn_error_t *
 
731
test_stringbuf_from_stream(apr_pool_t *pool)
 
732
{
 
733
  const char *test_cases[] =
 
734
    {
 
735
      "",
 
736
      "x",
 
737
      "this string is longer than the default 64 minimum block size used"
 
738
      "by the function under test",
 
739
      NULL
 
740
    };
 
741
 
 
742
  const char **test_case;
 
743
  for (test_case = test_cases; *test_case; ++test_case)
 
744
    {
 
745
      svn_stringbuf_t *result1, *result2, *result3, *result4;
 
746
      svn_stringbuf_t *original = svn_stringbuf_create(*test_case, pool);
 
747
 
 
748
      svn_stream_t *stream1 = svn_stream_from_stringbuf(original, pool);
 
749
      svn_stream_t *stream2 = svn_stream_from_stringbuf(original, pool);
 
750
 
 
751
      SVN_ERR(svn_stringbuf_from_stream(&result1, stream1, 0, pool));
 
752
      SVN_ERR(svn_stringbuf_from_stream(&result2, stream1, 0, pool));
 
753
      SVN_ERR(svn_stringbuf_from_stream(&result3, stream2, original->len,
 
754
                                        pool));
 
755
      SVN_ERR(svn_stringbuf_from_stream(&result4, stream2, original->len,
 
756
                                        pool));
 
757
 
 
758
      /* C-string contents must match */
 
759
      SVN_TEST_STRING_ASSERT(result1->data, original->data);
 
760
      SVN_TEST_STRING_ASSERT(result2->data, "");
 
761
      SVN_TEST_STRING_ASSERT(result3->data, original->data);
 
762
      SVN_TEST_STRING_ASSERT(result4->data, "");
 
763
 
 
764
      /* assumed length must match */
 
765
      SVN_TEST_ASSERT(result1->len == original->len);
 
766
      SVN_TEST_ASSERT(result2->len == 0);
 
767
      SVN_TEST_ASSERT(result3->len == original->len);
 
768
      SVN_TEST_ASSERT(result4->len == 0);
 
769
    }
 
770
 
 
771
  return SVN_NO_ERROR;
 
772
}
 
773
 
 
774
static svn_error_t *
 
775
empty_read_full_fn(void *baton, char *buffer, apr_size_t *len)
 
776
{
 
777
    *len = 0;
 
778
    return SVN_NO_ERROR;
 
779
}
 
780
 
 
781
static svn_error_t *
 
782
test_stream_compressed_read_full(apr_pool_t *pool)
 
783
{
 
784
  svn_stream_t *stream, *empty_stream;
 
785
  char buf[1];
 
786
  apr_size_t len;
 
787
 
 
788
  /* Reading an empty stream with read_full only support should not error. */
 
789
  empty_stream = svn_stream_create(NULL, pool);
 
790
 
 
791
  /* Create stream with only full read support. */
 
792
  svn_stream_set_read2(empty_stream, NULL, empty_read_full_fn);
 
793
 
 
794
  stream = svn_stream_compressed(empty_stream, pool);
 
795
  len = sizeof(buf);
 
796
  SVN_ERR(svn_stream_read_full(stream, buf, &len));
 
797
  if (len > 0)
 
798
    return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
 
799
                            "Got unexpected result.");
 
800
 
 
801
  SVN_ERR(svn_stream_close(stream));
 
802
 
 
803
  return SVN_NO_ERROR;
 
804
}
 
805
 
730
806
/* The test table.  */
731
807
 
732
 
struct svn_test_descriptor_t test_funcs[] =
 
808
static int max_threads = 1;
 
809
 
 
810
static struct svn_test_descriptor_t test_funcs[] =
733
811
  {
734
812
    SVN_TEST_NULL,
735
813
    SVN_TEST_PASS2(test_stream_from_string,
752
830
                   "test base64 encoding/decoding streams"),
753
831
    SVN_TEST_PASS2(test_stream_base64_2,
754
832
                   "base64 decoding allocation problem"),
 
833
    SVN_TEST_PASS2(test_stringbuf_from_stream,
 
834
                   "test svn_stringbuf_from_stream"),
 
835
    SVN_TEST_PASS2(test_stream_compressed_read_full,
 
836
                   "test compression for streams without partial read"),
755
837
    SVN_TEST_NULL
756
838
  };
 
839
 
 
840
SVN_TEST_MAIN