function verify_domain_by_url($url) { // echo "<br/>$url: [".$url."]"; $certificate_chain_length = load_certificate_chain($url); $result_array = get_chain_verification_results($certificate_chain_length, $url); $verification_result = verify_chain($result_array) ? "PASS" : "FAIL"; $result = get_company_data($url); $result['verification_result'] = $verification_result; $url_matching = match_urls(get_domain_from_url($url), $result['company_url']); $result['url_matching'] = $url_matching; // unset($result['company_url']); # we don't need it anymore after matching return $result; }
$bad_array = array('good', 'good', 'bad'); $bofa_url = 'https://www.bankofamerica.com'; $urls = ['https://www.foo.bar', 'http://www.foo.bar', 'httx://www.foo.bar', 'https://wwwfoobar', 'blard', 'https:/www.foo.bar', 'https:///www.foo.bar', null, '', ' ', 'https://colu.co']; $expected = array(TRUE, false, false, false, false, false, false, false, false, false, TRUE); foreach ($urls as &$key) { // $pattern = "/https:\/\/(\w*\.+)+/i"; // preg_match($pattern, $key) ? $key = 1: $key = 0; $key = verify_url($key); } // var_dump($urls); // echo "<br/>urls: [".$urls."]"; // TESTS // $var_test = ()? PASS:FAIL; $verify_url_test = $urls == $expected ? PASS : FAIL; echo "<br/>verify_url_test: [" . $verify_url_test . "]"; $array_test = verify_chain($good_array) == 1 && verify_chain($bad_array) != 1 ? PASS : FAIL; echo "<br/>array_test: [" . $array_test . "]"; $get_url_test = get_url($bofa_json) == $bofa_url ? PASS : get_url($bofa_json); echo "<br/>get_url_test: [" . $get_url_test . "]"; $get_empty_url_test = get_url(null) == '' ? PASS : get_url(null); echo "<br/>get_empty_url_test: [" . $get_empty_url_test . "]"; $match_domains_test = match_urls('www.foo.bar', 'xxx.foo.bar') && match_urls('www.foo.bar', '*.foo.bar') && match_urls('foo.bar', '*.foo.bar') && match_urls('foo.bar', 'www.foo.bar') && match_urls('cert-002.blockchain.info', 'www.blockchain.info') ? PASS : FAIL; echo "<br/>match_domains_test: [" . $match_domains_test . "]"; $get_domain_from_url_test = get_domain_from_url($bofa_url) == 'www.bankofamerica.com' ? PASS : FAIL; echo "<br/>get_domain_from_url_test: [" . $get_domain_from_url_test . "]"; $nothing = verify_domain_json(null); $null_test = $nothing["company_name"] == "" && $nothing["verification_result"] == 'FAIL' && $nothing["url_matching"] == 'false' ? PASS : FAIL; echo "<br/>null_test: [" . $null_test . "]"; if ($null_test == FAIL) { var_dump($nothing); }