/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.apache.coyote.http2;

import java.io.IOException;

import org.junit.Test;

public class TestHttp2Section_3_5 extends Http2TestBase {

    @Test(expected=IOException.class)
    public void testNoConnectionPreface() throws Exception {
        enableHttp2();
        configureAndStartWebApplication();
        openClientConnection();
        doHttpUpgrade();
        // Should send client preface here
        sendPing();
        // Send several pings else server will block waiting for the client
        // preface which is longer than a single ping.
        sendPing();
        sendPing();
        validateHttp2InitialResponse();
    }
}

@@ -870,16 +870,41 @@
 ption;%0A%0A
+import org.junit.Assert;%0A
 import o
@@ -991,36 +991,8 @@
 Test
-(expected=IOException.class)
 %0A   
@@ -1168,24 +1168,25 @@
 pUpgrade();%0A
+%0A
         // S
@@ -1189,269 +1189,1039 @@
 // S
-hould send client preface here%0A        sendPing();%0A        // Send several pings else server will block waiting for the client%0A        // preface which is longer than a single ping.%0A        sendPing();%0A        sendPing();%0A        validateHttp2InitialResponse();
+erver settings%0A        parser.readFrame(true);%0A        Assert.assertEquals(%220-Settings-%5B3%5D-%5B200%5D%5Cn%22 +%0A                %220-Settings-End%5Cn%22%0A                , output.getTrace());%0A        output.clearTrace();%0A%0A        // Should send client preface here. This will trigger an error.%0A        // Send two pings (2*(9+8)=34 bytes) as server looks for entire preface%0A        // of 24 bytes.%0A        sendPing();%0A        sendPing();%0A%0A        // If the client preface had been valid, this would be an%0A        // acknowledgement. Of the settings. As the preface was invalid, it%0A        // should be a GOAWAY frame.%0A        try %7B%0A            parser.readFrame(true);%0A            Assert.assertTrue(output.getTrace(), output.getTrace().startsWith(%220-Goaway-%5B1%5D-%5B1%5D-%5B%22));%0A        %7D catch (IOException ioe) %7B%0A            // Ignore%0A            // This is expected on some platforms and depends on timing. Once%0A            // the server closes the connection the client may see an exception%0A            // when trying to read the GOAWAY frame.%0A        %7D
 %0A   

Improve test for invalid client preface