WebTestCase(' Test_Of_User_Server_Cert '); } function testUserCert() { //echo "tLu 01"; $this->get('http://' . BASE_URL); // echo "tLu 011"; $this->assertWantedText('Login'); // echo "tLu 012"; $this->clickLink('Normal Login'); // Password Login //echo "tLu 013"; $this->assertWantedText('Pass Phrase:'); //echo "tLu 02\n"; $this->setField('email', NORMAL_USER1); $this->setField('pword', NORMAL_USER1_PW); $this->clickSubmit('Login'); //echo "tLu 021\n"; $this->assertWantedText('My Details'); $this->assertWantedText('Logout'); //echo "tLu 02"; $this->clickLink('+ Server Certificates'); $this->clickLink('New',1); $this->assertWantedText('Acceptable Use'); //echo "tLu 03"; $this->setField('rootcert', '2'); // Class 3 $this->setField('oldid', '10'); $this->setField('CSR',"-----BEGIN CERTIFICATE REQUEST-----\nMIIBmzCCAQQCAQAwWzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUx\nITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEUMBIGA1UEAxMLZXhh\nbXBsZS5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALTykrUbg+DzzN6A\nlkO0ErHvk/B7AEX5VANgLjQX6IWrx3nC5Nu3JCpk766xVMF+bJ+sbFL89w2jtG+v\nMzPfU6lCeAbaNBn6tFIch6NwT9VMi5HldeERdSR/NbXUS7Lf3SqI8qP3jPtB6KsJ\n1zb1hpWr1s+8la16NAYv5Ol9tUJfAgMBAAGgADANBgkqhkiG9w0BAQUFAAOBgQAu\n8qFD/KRCo3giB/EN6O+UgTyK6IsnA6gizbPoma1GubVwde7HX/xxuol8ChGaPAZw\n+1K2V4t6dV5qpHFZoLQONmyEi7qV11HMlMbk2aFDiOrs+011G6NT017yP/xcdYqN\n133TMpSZIXlLERjYsXKnrzVtYuCSbJqR5rZrT29D2Q==\n-----END CERTIFICATE REQUEST-----\n"); //echo "Jetzt wirds spannend ...\n"; $this->clickSubmit('Submit'); // echo $this->clickSubmit('Submit'); //echo "Und?\n"; //$text = $this->clickSubmitbyName('process'); //$text = $this->submitFormById('process'); // impossible no id on form // echo '**' . $this->post( // 'http://' . BASE_URL . '/account.php', // array('oldid' => '10', // 'rootcert' => '3', // 'CSR' => //'-----BEGIN CERTIFICATE REQUEST-----\n'. //'MIIBmzCCAQQCAQAwWzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUx\n'. //'ITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEUMBIGA1UEAxMLZXhh\n'. //'bXBsZS5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALTykrUbg+DzzN6A\n'. //'lkO0ErHvk/B7AEX5VANgLjQX6IWrx3nC5Nu3JCpk766xVMF+bJ+sbFL89w2jtG+v\n'. //'MzPfU6lCeAbaNBn6tFIch6NwT9VMi5HldeERdSR/NbXUS7Lf3SqI8qP3jPtB6KsJ\n'. //'1zb1hpWr1s+8la16NAYv5Ol9tUJfAgMBAAGgADANBgkqhkiG9w0BAQUFAAOBgQAu\n'. //'8qFD/KRCo3giB/EN6O+UgTyK6IsnA6gizbPoma1GubVwde7HX/xxuol8ChGaPAZw\n'. //'+1K2V4t6dV5qpHFZoLQONmyEi7qV11HMlMbk2aFDiOrs+011G6NT017yP/xcdYqN\n'. //'133TMpSZIXlLERjYsXKnrzVtYuCSbJqR5rZrT29D2Q==\n'. //'-----END CERTIFICATE REQUEST-----\n' // )) . '**'; $this->assertNoUnwantedText('hit the back button and try again'); $this->assertNoUnwantedText('Acceptable Use'); $this->assertNoUnwantedText('CommonName field was blank', 'CSR is not correct !!!'); $this->assertWantedText('Please make sure the following'); $this->assertWantedText( USER_1_CN ); echo "tLu 04\n"; $stringpage=$this->clickSubmit('Submit'); $this->assertWantedText('BEGIN CERTIFICATE'); $p1 = strpos($stringpage, '-----BEGIN CERTIFICATE-----'); $p2 = strpos($stringpage, '-----END CERTIFICATE-----')+25 ; // grab the certificate $cert = substr($stringpage, $p1, $p2-$p1); // get the DN from the certificate using openssl $handle1 = fopen("cert1.crt", "w"); fwrite($handle1, $cert); fclose($handle1); // fetch the DN of the cert $cmdline = "openssl x509 -in cert1.crt -noout -subject >cert1.txt"; exec($cmdline); unlink("cert1.crt"); $handle2 = fopen("cert1.txt", 'r'); $resultstring = fread($handle2, 512); fclose($handle2); // this removes the file unlink("cert1.txt"); echo $resultstring; $value = strpos($resultstring, USER_1_CN); // echo "Value: $value\n"; $this->assertTrue( $value, 'Common Name is not matching !'); } } ?>