~ubuntu-branches/ubuntu/precise/tomcat7/precise-proposed

« back to all changes in this revision

Viewing changes to test/org/apache/catalina/core/TestStandardContext.java

  • Committer: Bazaar Package Importer
  • Author(s): tony mancill
  • Date: 2011-07-25 22:58:33 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110725225833-1t773ak3y3g9utm2
Tags: 7.0.19-1
* Team upload.
* New upstream release.
  - Includes fix for CVE-2011-2526 (Closes: #634992)
* Remove patch for CVE-2011-2204 (included upstream).

Show diffs side-by-side

added added

removed removed

Lines of Context:
321
321
        
322
322
    }
323
323
 
 
324
    public void testBug51376a() throws Exception {
 
325
        doTestBug51376(false);
 
326
    }
 
327
 
 
328
    public void testBug51376b() throws Exception {
 
329
        doTestBug51376(true);
 
330
    }
 
331
 
 
332
    private void doTestBug51376(boolean loadOnStartUp) throws Exception {
 
333
 
 
334
        // Set up a container
 
335
        Tomcat tomcat = getTomcatInstance();
 
336
 
 
337
        // Must have a real docBase - just use temp
 
338
        File docBase = new File(System.getProperty("java.io.tmpdir"));
 
339
        Context ctx = tomcat.addContext("", docBase.getAbsolutePath());
 
340
 
 
341
        // Add ServletContainerInitializer
 
342
        Bug51376SCI sci = new Bug51376SCI(loadOnStartUp);
 
343
        ctx.addServletContainerInitializer(sci, null);
 
344
        
 
345
        // Start the context
 
346
        tomcat.start();
 
347
        
 
348
        // Stop the context
 
349
        ctx.stop();
 
350
        
 
351
        // Make sure that init() and destroy() were called correctly
 
352
        assertTrue(sci.getServlet().isOk());
 
353
    }
 
354
    
 
355
    public static final class Bug51376SCI
 
356
            implements ServletContainerInitializer {
 
357
 
 
358
        private Bug51376Servlet s = null;
 
359
        private boolean loadOnStartUp;
 
360
 
 
361
        public Bug51376SCI(boolean loadOnStartUp) {
 
362
            this.loadOnStartUp = loadOnStartUp;
 
363
        }
 
364
 
 
365
        private Bug51376Servlet getServlet() {
 
366
            return s;
 
367
        }
 
368
 
 
369
        @Override
 
370
        public void onStartup(Set<Class<?>> c, ServletContext ctx)
 
371
                throws ServletException {
 
372
            // Register and map servlet
 
373
            s = new Bug51376Servlet();
 
374
            ServletRegistration.Dynamic sr = ctx.addServlet("bug51376", s);
 
375
            sr.addMapping("/bug51376");
 
376
            if (loadOnStartUp) {
 
377
                sr.setLoadOnStartup(1);
 
378
            }
 
379
        }
 
380
    }
 
381
    
 
382
    public static final class Bug51376Servlet extends HttpServlet {
 
383
 
 
384
        private static final long serialVersionUID = 1L;
 
385
 
 
386
        private Boolean initOk = null;
 
387
        private Boolean destoryOk = null;
 
388
        
 
389
        @Override
 
390
        public void init() {
 
391
            if (initOk == null && destoryOk == null) {
 
392
                initOk = Boolean.TRUE;
 
393
            } else {
 
394
                initOk = Boolean.FALSE;
 
395
            }
 
396
        }
 
397
 
 
398
        @Override
 
399
        public void destroy() {
 
400
            if (initOk.booleanValue() && destoryOk == null) {
 
401
                destoryOk = Boolean.TRUE;
 
402
            } else {
 
403
                destoryOk = Boolean.FALSE;
 
404
            }
 
405
        }
 
406
 
 
407
        @Override
 
408
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
 
409
                throws ServletException, IOException {
 
410
            resp.setContentType("text/plain");
 
411
            resp.getWriter().write("OK");
 
412
        }
 
413
        
 
414
        protected boolean isOk() {
 
415
            if (initOk != null && initOk.booleanValue() && destoryOk != null &&
 
416
                    destoryOk.booleanValue()) {
 
417
                return true;
 
418
            } else if (initOk == null && destoryOk == null) {
 
419
                return true;
 
420
            } else {
 
421
                return false;
 
422
            }
 
423
        }
 
424
    }
 
425
 
324
426
    /**
325
427
     * Test case for bug 49711: HttpServletRequest.getParts does not work
326
428
     * in a filter.