From be7de92a31c224f36c01d1d06de1bb53e6e1161b Mon Sep 17 00:00:00 2001
From: Daniel Beck
+ * If allowLocal is true, the TLD is checked using {@link #isValidLocalTld(String)}. + * The TLD is then checked against {@link #isValidInfrastructureTld(String)}, + * {@link #isValidGenericTld(String)} and {@link #isValidCountryCodeTld(String)} * @param tld the parameter to check for TLD status, not null * @return true if the parameter is a TLD */ public boolean isValidTld(String tld) { - tld = unicodeToASCII(tld); if(allowLocal && isValidLocalTld(tld)) { return true; } @@ -230,8 +353,8 @@ public boolean isValidInfrastructureTld(String iTld) { */ public boolean isValidGenericTld(String gTld) { final String key = chompLeadingDot(unicodeToASCII(gTld).toLowerCase(Locale.ENGLISH)); - return (arrayContains(GENERIC_TLDS, key) || arrayContains(genericTLDsPlus, key)) - && !arrayContains(genericTLDsMinus, key); + return (arrayContains(GENERIC_TLDS, key) || arrayContains(mygenericTLDsPlus, key)) + && !arrayContains(mygenericTLDsMinus, key); } /** @@ -243,8 +366,8 @@ public boolean isValidGenericTld(String gTld) { */ public boolean isValidCountryCodeTld(String ccTld) { final String key = chompLeadingDot(unicodeToASCII(ccTld).toLowerCase(Locale.ENGLISH)); - return (arrayContains(COUNTRY_CODE_TLDS, key) || arrayContains(countryCodeTLDsPlus, key)) - && !arrayContains(countryCodeTLDsMinus, key); + return (arrayContains(COUNTRY_CODE_TLDS, key) || arrayContains(mycountryCodeTLDsPlus, key)) + && !arrayContains(mycountryCodeTLDsMinus, key); } /** @@ -256,7 +379,18 @@ public boolean isValidCountryCodeTld(String ccTld) { */ public boolean isValidLocalTld(String lTld) { final String key = chompLeadingDot(unicodeToASCII(lTld).toLowerCase(Locale.ENGLISH)); - return arrayContains(LOCAL_TLDS, key); + return (arrayContains(LOCAL_TLDS, key) || arrayContains(mylocalTLDsPlus, key)) + && !arrayContains(mylocalTLDsMinus, key); + } + + /** + * Does this instance allow local addresses? + * + * @return true if local addresses are allowed. + * @since 1.7 + */ + public boolean isAllowLocal() { + return this.allowLocal; } private String chompLeadingDot(String str) { @@ -288,7 +422,7 @@ private String chompLeadingDot(String str) { // WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search private static final String[] GENERIC_TLDS = new String[] { - // Taken from Version 2017020400, Last Updated Sat Feb 4 07:07:01 2017 UTC + // Taken from Version 2020073100, Last Updated Fri Jul 31 07:07:01 2020 UTC "aaa", // aaa American Automobile Association, Inc. "aarp", // aarp AARP "abarth", // abarth Fiat Chrysler Automobiles N.V. @@ -304,7 +438,7 @@ private String chompLeadingDot(String str) { "accountant", // accountant dot Accountant Limited "accountants", // accountants Knob Town, LLC "aco", // aco ACO Severin Ahlmann GmbH & Co. KG - "active", // active The Active Network, Inc +// "active", // active The Active Network, Inc "actor", // actor United TLD Holdco Ltd. "adac", // adac Allgemeiner Deutscher Automobil-Club e.V. (ADAC) "ads", // ads Charleston Road Registry Inc. @@ -314,10 +448,11 @@ private String chompLeadingDot(String str) { "aetna", // aetna Aetna Life Insurance Company "afamilycompany", // afamilycompany Johnson Shareholdings, Inc. "afl", // afl Australian Football League + "africa", // africa ZA Central Registry NPC trading as Registry.Africa "agakhan", // agakhan Fondation Aga Khan (Aga Khan Foundation) "agency", // agency Steel Falls, LLC "aig", // aig American International Group, Inc. - "aigo", // aigo aigo Digital Technology Co,Ltd. +// "aigo", // aigo aigo Digital Technology Co,Ltd. [Not assigned as of Jul 25] "airbus", // airbus Airbus S.A.S. "airforce", // airforce United TLD Holdco Ltd. "airtel", // airtel Bharti Airtel Limited @@ -330,6 +465,7 @@ private String chompLeadingDot(String str) { "ally", // ally Ally Financial Inc. "alsace", // alsace REGION D ALSACE "alstom", // alstom ALSTOM + "amazon", // amazon Amazon Registry Services, Inc. "americanexpress", // americanexpress American Express Travel Related Services Company, Inc. "americanfamily", // americanfamily AmFam, Inc. "amex", // amex American Express Travel Related Services Company, Inc. @@ -345,6 +481,7 @@ private String chompLeadingDot(String str) { "app", // app Charleston Road Registry Inc. "apple", // apple Apple Inc. "aquarelle", // aquarelle Aquarelle.com + "arab", // arab League of Arab States "aramco", // aramco Aramco Services Company "archi", // archi STARTING DOT LIMITED "army", // army United TLD Holdco Ltd. @@ -406,14 +543,14 @@ private String chompLeadingDot(String str) { "biz", // biz Neustar, Inc. "black", // black Afilias Limited "blackfriday", // blackfriday Uniregistry, Corp. - "blanco", // blanco BLANCO GmbH + Co KG +// "blanco", // blanco BLANCO GmbH + Co KG "blockbuster", // blockbuster Dish DBS Corporation "blog", // blog Knock Knock WHOIS There, LLC "bloomberg", // bloomberg Bloomberg IP Holdings LLC "blue", // blue Afilias Limited "bms", // bms Bristol-Myers Squibb Company "bmw", // bmw Bayerische Motoren Werke Aktiengesellschaft - "bnl", // bnl Banca Nazionale del Lavoro +// "bnl", // bnl Banca Nazionale del Lavoro "bnpparibas", // bnpparibas BNP Paribas "boats", // boats DERBoats, LLC "boehringer", // boehringer Boehringer Ingelheim International GmbH @@ -423,7 +560,7 @@ private String chompLeadingDot(String str) { "boo", // boo Charleston Road Registry Inc. "book", // book Amazon Registry Services, Inc. "booking", // booking Booking.com B.V. - "boots", // boots THE BOOTS COMPANY PLC +// "boots", // boots THE BOOTS COMPANY PLC "bosch", // bosch Robert Bosch GMBH "bostik", // bostik Bostik SA "boston", // boston Boston TLD Management, LLC @@ -464,7 +601,7 @@ private String chompLeadingDot(String str) { "career", // career dotCareer LLC "careers", // careers Wild Corner, LLC "cars", // cars Uniregistry, Corp. - "cartier", // cartier Richemont DNS Inc. +// "cartier", // cartier Richemont DNS Inc. "casa", // casa Top Level Domain Holdings Limited "case", // case CNH Industrial N.V. "caseih", // caseih CNH Industrial N.V. @@ -485,14 +622,15 @@ private String chompLeadingDot(String str) { "cfd", // cfd DOTCFD REGISTRY LTD "chanel", // chanel Chanel International B.V. "channel", // channel Charleston Road Registry Inc. + "charity", // charity Corn Lake, LLC "chase", // chase JPMorgan Chase & Co. "chat", // chat Sand Fields, LLC "cheap", // cheap Sand Cover, LLC "chintai", // chintai CHINTAI Corporation - "chloe", // chloe Richemont DNS Inc. +// "chloe", // chloe Richemont DNS Inc. (Not assigned) "christmas", // christmas Uniregistry, Corp. "chrome", // chrome Charleston Road Registry Inc. - "chrysler", // chrysler FCA US LLC. +// "chrysler", // chrysler FCA US LLC. "church", // church Holly Fileds, LLC "cipriani", // cipriani Hotel Cipriani Srl "circle", // circle Amazon Registry Services, Inc. @@ -538,6 +676,7 @@ private String chompLeadingDot(String str) { "coupon", // coupon Amazon Registry Services, Inc. "coupons", // coupons Black Island, LLC "courses", // courses OPEN UNIVERSITIES AUSTRALIA PTY LTD + "cpa", // cpa American Institute of Certified Public Accountants "credit", // credit Snow Shadow, LLC "creditcard", // creditcard Binky Frostbite, LLC "creditunion", // creditunion CUNA Performance Resources, LLC @@ -587,9 +726,9 @@ private String chompLeadingDot(String str) { "dnp", // dnp Dai Nippon Printing Co., Ltd. "docs", // docs Charleston Road Registry Inc. "doctor", // doctor Brice Trail, LLC - "dodge", // dodge FCA US LLC. +// "dodge", // dodge FCA US LLC. "dog", // dog Koko Mill, LLC - "doha", // doha Communications Regulatory Authority (CRA) +// "doha", // doha Communications Regulatory Authority (CRA) "domains", // domains Sugar Cross, LLC // "doosan", // doosan Doosan Corporation (retired) "dot", // dot Dish DBS Corporation @@ -599,7 +738,7 @@ private String chompLeadingDot(String str) { "dubai", // dubai Dubai Smart Government Department "duck", // duck Johnson Shareholdings, Inc. "dunlop", // dunlop The Goodyear Tire & Rubber Company - "duns", // duns The Dun & Bradstreet Corporation +// "duns", // duns The Dun & Bradstreet Corporation "dupont", // dupont E. I. du Pont de Nemours and Company "durban", // durban ZA Central Registry NPC trading as ZA Central Registry "dvag", // dvag Deutsche Vermögensberatung Aktiengesellschaft DVAG @@ -616,18 +755,19 @@ private String chompLeadingDot(String str) { "engineer", // engineer United TLD Holdco Ltd. "engineering", // engineering Romeo Canyon "enterprises", // enterprises Snow Oaks, LLC - "epost", // epost Deutsche Post AG +// "epost", // epost Deutsche Post AG "epson", // epson Seiko Epson Corporation "equipment", // equipment Corn Station, LLC "ericsson", // ericsson Telefonaktiebolaget L M Ericsson "erni", // erni ERNI Group Holding AG "esq", // esq Charleston Road Registry Inc. "estate", // estate Trixy Park, LLC - "esurance", // esurance Esurance Insurance Company + // "esurance", // esurance Esurance Insurance Company (not assigned as at Version 2020062100) + "etisalat", // etisalat Emirates Telecommunic "eurovision", // eurovision European Broadcasting Union (EBU) "eus", // eus Puntueus Fundazioa "events", // events Pioneer Maple, LLC - "everbank", // everbank EverBank +// "everbank", // everbank EverBank "exchange", // exchange Spring Falls, LLC "expert", // expert Magic Pass, LLC "exposed", // exposed Victor Beach, LLC @@ -701,6 +841,7 @@ private String chompLeadingDot(String str) { "games", // games United TLD Holdco Ltd. "gap", // gap The Gap, Inc. "garden", // garden Top Level Domain Holdings Limited + "gay", // gay Top Level Design, LLC "gbiz", // gbiz Charleston Road Registry Inc. "gdn", // gdn Joint Stock Company "Navigation-information systems" "gea", // gea GEA Group Aktiengesellschaft @@ -726,7 +867,7 @@ private String chompLeadingDot(String str) { "goldpoint", // goldpoint YODOBASHI CAMERA CO.,LTD. "golf", // golf Lone Falls, LLC "goo", // goo NTT Resonant Inc. - "goodhands", // goodhands Allstate Fire and Casualty Insurance Company +// "goodhands", // goodhands Allstate Fire and Casualty Insurance Company "goodyear", // goodyear The Goodyear Tire & Rubber Company "goog", // goog Charleston Road Registry Inc. "google", // google Charleston Road Registry Inc. @@ -738,6 +879,7 @@ private String chompLeadingDot(String str) { "gratis", // gratis Pioneer Tigers, LLC "green", // green Afilias Limited "gripe", // gripe Corn Sunset, LLC + "grocery", // grocery Wal-Mart Stores, Inc. "group", // group Romeo Town, LLC "guardian", // guardian The Guardian Life Insurance Company of America "gucci", // gucci Guccio Gucci S.p.a. @@ -772,18 +914,19 @@ private String chompLeadingDot(String str) { "homes", // homes DERHomes, LLC "homesense", // homesense The TJX Companies, Inc. "honda", // honda Honda Motor Co., Ltd. - "honeywell", // honeywell Honeywell GTLD LLC +// "honeywell", // honeywell Honeywell GTLD LLC "horse", // horse Top Level Domain Holdings Limited "hospital", // hospital Ruby Pike, LLC "host", // host DotHost Inc. "hosting", // hosting Uniregistry, Corp. "hot", // hot Amazon Registry Services, Inc. "hoteles", // hoteles Travel Reservations SRL + "hotels", // hotels Booking.com B.V. "hotmail", // hotmail Microsoft Corporation "house", // house Sugar Park, LLC "how", // how Charleston Road Registry Inc. "hsbc", // hsbc HSBC Holdings PLC - "htc", // htc HTC corporation +// "htc", // htc HTC corporation (Not assigned) "hughes", // hughes Hughes Satellite Systems Corporation "hyatt", // hyatt Hyatt GTLD, L.L.C. "hyundai", // hyundai Hyundai Motor Company @@ -799,6 +942,7 @@ private String chompLeadingDot(String str) { "imdb", // imdb Amazon Registry Services, Inc. "immo", // immo Auburn Bloom, LLC "immobilien", // immobilien United TLD Holdco Ltd. + "inc", // inc Intercap Holdings Inc. "industries", // industries Outer House, LLC "infiniti", // infiniti NISSAN MOTOR CO., LTD. "info", // info Afilias Limited @@ -814,14 +958,14 @@ private String chompLeadingDot(String str) { "investments", // investments Holly Glen, LLC "ipiranga", // ipiranga Ipiranga Produtos de Petroleo S.A. "irish", // irish Dot-Irish LLC - "iselect", // iselect iSelect Ltd +// "iselect", // iselect iSelect Ltd "ismaili", // ismaili Fondation Aga Khan (Aga Khan Foundation) "ist", // ist Istanbul Metropolitan Municipality "istanbul", // istanbul Istanbul Metropolitan Municipality / Medya A.S. "itau", // itau Itau Unibanco Holding S.A. "itv", // itv ITV Services Limited "iveco", // iveco CNH Industrial N.V. - "iwc", // iwc Richemont DNS Inc. +// "iwc", // iwc Richemont DNS Inc. "jaguar", // jaguar Jaguar Land Rover Ltd "java", // java Oracle Corporation "jcb", // jcb JCB Co., Ltd. @@ -830,7 +974,7 @@ private String chompLeadingDot(String str) { "jetzt", // jetzt New TLD Company AB "jewelry", // jewelry Wild Bloom, LLC "jio", // jio Affinity Names, Inc. - "jlc", // jlc Richemont DNS Inc. +// "jlc", // jlc Richemont DNS Inc. "jll", // jll Jones Lang LaSalle Incorporated "jmp", // jmp Matrix IP LLC "jnj", // jnj Johnson & Johnson Services, Inc. @@ -864,12 +1008,12 @@ private String chompLeadingDot(String str) { "kuokgroup", // kuokgroup Kerry Trading Co. Limited "kyoto", // kyoto Academic Institution: Kyoto Jyoho Gakuen "lacaixa", // lacaixa CAIXA D'ESTALVIS I PENSIONS DE BARCELONA - "ladbrokes", // ladbrokes LADBROKES INTERNATIONAL PLC +// "ladbrokes", // ladbrokes LADBROKES INTERNATIONAL PLC "lamborghini", // lamborghini Automobili Lamborghini S.p.A. "lamer", // lamer The Estée Lauder Companies Inc. "lancaster", // lancaster LANCASTER "lancia", // lancia Fiat Chrysler Automobiles N.V. - "lancome", // lancome L'Oréal +// "lancome", // lancome L'Oréal "land", // land Pine Moon, LLC "landrover", // landrover Jaguar Land Rover Ltd "lanxess", // lanxess LANXESS Corporation @@ -887,7 +1031,7 @@ private String chompLeadingDot(String str) { "lego", // lego LEGO Juris A/S "lexus", // lexus TOYOTA MOTOR CORPORATION "lgbt", // lgbt Afilias Limited - "liaison", // liaison Liaison Technologies, Incorporated +// "liaison", // liaison Liaison Technologies, Incorporated "lidl", // lidl Schwarz Domains und Services GmbH & Co. KG "life", // life Trixy Oaks, LLC "lifeinsurance", // lifeinsurance American Council of Life Insurers @@ -904,6 +1048,8 @@ private String chompLeadingDot(String str) { "live", // live United TLD Holdco Ltd. "living", // living Lifestyle Domain Holdings, Inc. "lixil", // lixil LIXIL Group Corporation + "llc", // llc Afilias plc + "llp", // llp Dot Registry LLC "loan", // loan dot Loan Limited "loans", // loans June Woods, LLC "locker", // locker Dish DBS Corporation @@ -930,6 +1076,7 @@ private String chompLeadingDot(String str) { "man", // man MAN SE "management", // management John Goodbye, LLC "mango", // mango PUNTO FA S.L. + "map", // map Charleston Road Registry Inc. "market", // market Unitied TLD Holdco, Ltd "marketing", // marketing Fern Pass, LLC "markets", // markets DOTMARKETS REGISTRY LTD @@ -938,8 +1085,8 @@ private String chompLeadingDot(String str) { "maserati", // maserati Fiat Chrysler Automobiles N.V. "mattel", // mattel Mattel Sites, Inc. "mba", // mba Lone Hollow, LLC - "mcd", // mcd McDonald’s Corporation - "mcdonalds", // mcdonalds McDonald’s Corporation +// "mcd", // mcd McDonald’s Corporation (Not assigned) +// "mcdonalds", // mcdonalds McDonald’s Corporation (Not assigned) "mckinsey", // mckinsey McKinsey Holdings, Inc. "med", // med Medistry LLC "media", // media Grand Glen, LLC @@ -949,7 +1096,8 @@ private String chompLeadingDot(String str) { "memorial", // memorial Dog Beach, LLC "men", // men Exclusive Registry Limited "menu", // menu Wedding TLD2, LLC - "meo", // meo PT Comunicacoes S.A. +// "meo", // meo PT Comunicacoes S.A. + "merckmsd", // merckmsd MSD Registry Holdings, Inc. "metlife", // metlife MetLife Services and Solutions, LLC "miami", // miami Top Level Domain Holdings Limited "microsoft", // microsoft Microsoft Corporation @@ -963,7 +1111,7 @@ private String chompLeadingDot(String str) { "mma", // mma MMA IARD "mobi", // mobi Afilias Technologies Limited dba dotMobi "mobile", // mobile Dish DBS Corporation - "mobily", // mobily GreenTech Consultancy Company W.L.L. +// "mobily", // mobily GreenTech Consultancy Company W.L.L. "moda", // moda United TLD Holdco Ltd. "moe", // moe Interlink Co., Ltd. "moi", // moi Amazon Registry Services, Inc. @@ -971,8 +1119,8 @@ private String chompLeadingDot(String str) { "monash", // monash Monash University "money", // money Outer McCook, LLC "monster", // monster Monster Worldwide, Inc. - "montblanc", // montblanc Richemont DNS Inc. - "mopar", // mopar FCA US LLC. +// "montblanc", // montblanc Richemont DNS Inc. (Not assigned) +// "mopar", // mopar FCA US LLC. "mormon", // mormon IRI Domain Management, LLC ("Applicant") "mortgage", // mortgage United TLD Holdco, Ltd "moscow", // moscow Foundation for Assistance for Internet Technologies and Infrastructure Development (FAITID) @@ -980,16 +1128,16 @@ private String chompLeadingDot(String str) { "motorcycles", // motorcycles DERMotorcycles, LLC "mov", // mov Charleston Road Registry Inc. "movie", // movie New Frostbite, LLC - "movistar", // movistar Telefónica S.A. +// "movistar", // movistar Telefónica S.A. "msd", // msd MSD Registry Holdings, Inc. "mtn", // mtn MTN Dubai Limited - "mtpc", // mtpc Mitsubishi Tanabe Pharma Corporation +// "mtpc", // mtpc Mitsubishi Tanabe Pharma Corporation (Retired) "mtr", // mtr MTR Corporation Limited "museum", // museum Museum Domain Management Association "mutual", // mutual Northwestern Mutual MU TLD Registry, LLC // "mutuelle", // mutuelle Fédération Nationale de la Mutualité Française (Retired) "nab", // nab National Australia Bank Limited - "nadex", // nadex Nadex Domains, Inc +// "nadex", // nadex Nadex Domains, Inc "nagoya", // nagoya GMO Registry, Inc. "name", // name VeriSign Information Services, Inc. "nationwide", // nationwide Nationwide Mutual Insurance Company @@ -1048,16 +1196,16 @@ private String chompLeadingDot(String str) { "orange", // orange Orange Brand Services Limited "org", // org Public Interest Registry (PIR) "organic", // organic Afilias Limited - "orientexpress", // orientexpress Orient Express +// "orientexpress", // orientexpress Orient Express (retired 2017-04-11) "origins", // origins The Estée Lauder Companies Inc. "osaka", // osaka Interlink Co., Ltd. "otsuka", // otsuka Otsuka Holdings Co., Ltd. "ott", // ott Dish DBS Corporation "ovh", // ovh OVH SAS "page", // page Charleston Road Registry Inc. - "pamperedchef", // pamperedchef The Pampered Chef, Ltd. +// "pamperedchef", // pamperedchef The Pampered Chef, Ltd. (Not assigned) "panasonic", // panasonic Panasonic Corporation - "panerai", // panerai Richemont DNS Inc. +// "panerai", // panerai Richemont DNS Inc. "paris", // paris City of Paris "pars", // pars Asia Green IT System Bilgisayar San. ve Tic. Ltd. Sti. "partners", // partners Magic Glen, LLC @@ -1069,13 +1217,14 @@ private String chompLeadingDot(String str) { "pet", // pet Afilias plc "pfizer", // pfizer Pfizer Inc. "pharmacy", // pharmacy National Association of Boards of Pharmacy + "phd", // phd Charleston Road Registry Inc. "philips", // philips Koninklijke Philips N.V. "phone", // phone Dish DBS Corporation "photo", // photo Uniregistry, Corp. "photography", // photography Sugar Glen, LLC "photos", // photos Sea Corner, LLC "physio", // physio PhysBiz Pty Ltd - "piaget", // piaget Richemont DNS Inc. +// "piaget", // piaget Richemont DNS Inc. "pics", // pics Uniregistry, Corp. "pictet", // pictet Pictet Europe S.A. "pictures", // pictures Foggy Sky, LLC @@ -1147,7 +1296,7 @@ private String chompLeadingDot(String str) { "rich", // rich I-REGISTRY Ltd., Niederlassung Deutschland "richardli", // richardli Pacific Century Asset Management (HK) Limited "ricoh", // ricoh Ricoh Company, Ltd. - "rightathome", // rightathome Johnson Shareholdings, Inc. + // "rightathome", // rightathome Johnson Shareholdings, Inc. (retired 2020-07-31) "ril", // ril Reliance Industries Limited "rio", // rio Empresa Municipal de Informática SA - IPLANRIO "rip", // rip United TLD Holdco Ltd. @@ -1158,6 +1307,7 @@ private String chompLeadingDot(String str) { "rogers", // rogers Rogers Communications Canada Inc. "room", // room Amazon Registry Services, Inc. "rsvp", // rsvp Charleston Road Registry Inc. + "rugby", // rugby World Rugby Strategic Developments Limited "ruhr", // ruhr regiodot GmbH & Co. KG "run", // run Snow Park, LLC "rwe", // rwe RWE AG @@ -1174,7 +1324,7 @@ private String chompLeadingDot(String str) { "sandvikcoromant", // sandvikcoromant Sandvik AB "sanofi", // sanofi Sanofi "sap", // sap SAP AG - "sapo", // sapo PT Comunicacoes S.A. +// "sapo", // sapo PT Comunicacoes S.A. "sarl", // sarl Delta Orchard, LLC "sas", // sas Research IP LLC "save", // save Amazon Registry Services, Inc. @@ -1191,8 +1341,9 @@ private String chompLeadingDot(String str) { "schwarz", // schwarz Schwarz Domains und Services GmbH & Co. KG "science", // science dot Science Limited "scjohnson", // scjohnson Johnson Shareholdings, Inc. - "scor", // scor SCOR SE + // "scor", // scor SCOR SE (not assigned as at Version 2020062100) "scot", // scot Dot Scot Registry Limited + "search", // search Charleston Road Registry Inc. "seat", // seat SEAT, S.A. (Sociedad Unipersonal) "secure", // secure Amazon Registry Services, Inc. "security", // security XYZ.COM LLC @@ -1242,18 +1393,19 @@ private String chompLeadingDot(String str) { "sony", // sony Sony Corporation "soy", // soy Charleston Road Registry Inc. "space", // space DotSpace Inc. - "spiegel", // spiegel SPIEGEL-Verlag Rudolf Augstein GmbH & Co. KG +// "spiegel", // spiegel SPIEGEL-Verlag Rudolf Augstein GmbH & Co. KG + "sport", // sport Global Association of International Sports Federations (GAISF) "spot", // spot Amazon Registry Services, Inc. "spreadbetting", // spreadbetting DOTSPREADBETTING REGISTRY LTD "srl", // srl InterNetX Corp. - "srt", // srt FCA US LLC. +// "srt", // srt FCA US LLC. "stada", // stada STADA Arzneimittel AG "staples", // staples Staples, Inc. "star", // star Star India Private Limited - "starhub", // starhub StarHub Limited +// "starhub", // starhub StarHub Limited "statebank", // statebank STATE BANK OF INDIA "statefarm", // statefarm State Farm Mutual Automobile Insurance Company - "statoil", // statoil Statoil ASA +// "statoil", // statoil Statoil ASA "stc", // stc Saudi Telecom Company "stcgroup", // stcgroup Saudi Telecom Company "stockholm", // stockholm Stockholms kommun @@ -1274,7 +1426,7 @@ private String chompLeadingDot(String str) { "swiftcover", // swiftcover Swiftcover Insurance Services Limited "swiss", // swiss Swiss Confederation "sydney", // sydney State of New South Wales, Department of Premier and Cabinet - "symantec", // symantec Symantec Corporation +// "symantec", // symantec Symantec Corporation [Not assigned as of Jul 25] "systems", // systems Dash Cypress, LLC "tab", // tab Tabcorp Holdings Limited "taipei", // taipei Taipei City Government @@ -1282,7 +1434,7 @@ private String chompLeadingDot(String str) { "taobao", // taobao Alibaba Group Holding Limited "target", // target Target Domain Holdings, LLC "tatamotors", // tatamotors Tata Motors Ltd - "tatar", // tatar Limited Liability Company "Coordination Center of Regional Domain of Tatarstan Republic" + "tatar", // tatar LLC "Coordination Center of Regional Domain of Tatarstan Republic" "tattoo", // tattoo Uniregistry, Corp. "tax", // tax Storm Orchard, LLC "taxi", // taxi Pine Falls, LLC @@ -1292,8 +1444,8 @@ private String chompLeadingDot(String str) { "tech", // tech Dot Tech LLC "technology", // technology Auburn Falls, LLC "tel", // tel Telnic Ltd. - "telecity", // telecity TelecityGroup International Limited - "telefonica", // telefonica Telefónica S.A. +// "telecity", // telecity TelecityGroup International Limited +// "telefonica", // telefonica Telefónica S.A. "temasek", // temasek Temasek Holdings (Private) Limited "tennis", // tennis Cotton Bloom, LLC "teva", // teva Teva Pharmaceutical Industries Limited @@ -1338,7 +1490,7 @@ private String chompLeadingDot(String str) { "tvs", // tvs T V SUNDRAM IYENGAR & SONS PRIVATE LIMITED "ubank", // ubank National Australia Bank Limited "ubs", // ubs UBS AG - "uconnect", // uconnect FCA US LLC. +// "uconnect", // uconnect FCA US LLC. "unicom", // unicom China United Network Communications Corporation Limited "university", // university Little Station, LLC "uno", // uno Dot Latin LLC @@ -1362,8 +1514,8 @@ private String chompLeadingDot(String str) { "virgin", // virgin Virgin Enterprises Limited "visa", // visa Visa Worldwide Pte. Limited "vision", // vision Koko Station, LLC - "vista", // vista Vistaprint Limited - "vistaprint", // vistaprint Vistaprint Limited +// "vista", // vista Vistaprint Limited +// "vistaprint", // vistaprint Vistaprint Limited "viva", // viva Saudi Telecom Company "vivo", // vivo Telefonica Brasil S.A. "vlaanderen", // vlaanderen DNS.be vzw @@ -1380,7 +1532,7 @@ private String chompLeadingDot(String str) { "walter", // walter Sandvik AB "wang", // wang Zodiac Registry Limited "wanggou", // wanggou Amazon Registry Services, Inc. - "warman", // warman Weir Group IP Limited +// "warman", // warman Weir Group IP Limited "watch", // watch Sand Shadow, LLC "watches", // watches Richemont DNS Inc. "weather", // weather The Weather Channel, LLC @@ -1445,6 +1597,7 @@ private String chompLeadingDot(String str) { "xn--c1avg", // орг Public Interest Registry "xn--c2br7g", // नेट VeriSign Sarl "xn--cck2b3b", // ストア Amazon Registry Services, Inc. + "xn--cckwcxetd", // アマゾン Amazon Registry Services, Inc. "xn--cg4bki", // 삼성 SAMSUNG SDS CO., LTD "xn--czr694b", // 商标 HU YI GLOBAL INFORMATION RESOURCES(HOLDING) COMPANY.HONGKONG LIMITED "xn--czrs0t", // 商店 Wild Island, LLC @@ -1452,7 +1605,7 @@ private String chompLeadingDot(String str) { "xn--d1acj3b", // дети The Foundation for Network Initiatives “The Smart Internet” "xn--eckvdtc9d", // ポイント Amazon Registry Services, Inc. "xn--efvy88h", // 新闻 Xinhua News Agency Guangdong Branch 新华通讯社广东分社 - "xn--estv75g", // 工行 Industrial and Commercial Bank of China Limited +// "xn--estv75g", // 工行 Industrial and Commercial Bank of China Limited "xn--fct429k", // 家電 Amazon Registry Services, Inc. "xn--fhbei", // كوم VeriSign Sarl "xn--fiq228c5hs", // 中文网 TLD REGISTRY LIMITED @@ -1468,15 +1621,17 @@ private String chompLeadingDot(String str) { "xn--imr513n", // 餐厅 HU YI GLOBAL INFORMATION RESOURCES (HOLDING) COMPANY. HONGKONG LIMITED "xn--io0a7i", // 网络 Computer Network Information Center of Chinese Academy of Sciences (China Internet Network Information Center) "xn--j1aef", // ком VeriSign Sarl + "xn--jlq480n2rg", // 亚马逊 Amazon Registry Services, Inc. "xn--jlq61u9w7b", // 诺基亚 Nokia Corporation "xn--jvr189m", // 食品 Amazon Registry Services, Inc. "xn--kcrx77d1x4a", // 飞利浦 Koninklijke Philips N.V. - "xn--kpu716f", // 手表 Richemont DNS Inc. +// "xn--kpu716f", // 手表 Richemont DNS Inc. [Not assigned as of Jul 25] "xn--kput3i", // 手机 Beijing RITT-Net Technology Development Co., Ltd "xn--mgba3a3ejt", // ارامكو Aramco Services Company "xn--mgba7c0bbn0a", // العليان Crescent Holding GmbH + "xn--mgbaakc7dvf", // اتصالات Emirates Telecommunications Corporation (trading as Etisalat) "xn--mgbab2bd", // بازار CORE Association - "xn--mgbb9fbpob", // موبايلي GreenTech Consultancy Company W.L.L. +// "xn--mgbb9fbpob", // موبايلي GreenTech Consultancy Company W.L.L. "xn--mgbca7dzdo", // ابوظبي Abu Dhabi Systems and Information Centre "xn--mgbi4ecexp", // كاثوليك Pontificium Consilium de Comunicationibus Socialibus (PCCS) (Pontifical Council for Social Communication) "xn--mgbt3dhd", // همراه Asia Green IT System Bilgisayar San. ve Tic. Ltd. Sti. @@ -1484,11 +1639,13 @@ private String chompLeadingDot(String str) { "xn--mxtq1m", // 政府 Net-Chinese Co., Ltd. "xn--ngbc5azd", // شبكة International Domain Registry Pty. Ltd. "xn--ngbe9e0a", // بيتك Kuwait Finance House + "xn--ngbrx", // عرب League of Arab States "xn--nqv7f", // 机构 Public Interest Registry "xn--nqv7fs00ema", // 组织机构 Public Interest Registry "xn--nyqy26a", // 健康 Stable Tone Limited + "xn--otu796d", // 招聘 Dot Trademark TLD Holding Company Limited "xn--p1acf", // рус Rusnames Limited - "xn--pbt977c", // 珠宝 Richemont DNS Inc. +// "xn--pbt977c", // 珠宝 Richemont DNS Inc. [Not assigned as of Jul 25] "xn--pssy2u", // 大拿 VeriSign Sarl "xn--q9jyb4c", // みんな Charleston Road Registry Inc. "xn--qcka1pmc", // グーグル Charleston Road Registry Inc. @@ -1507,7 +1664,7 @@ private String chompLeadingDot(String str) { "xn--w4rs40l", // 嘉里 Kerry Trading Co. Limited "xn--xhq521b", // 广东 Guangzhou YU Wei Information Technology Co., Ltd. "xn--zfr164b", // 政务 China Organizational Name Administration Center - "xperia", // xperia Sony Mobile Communications AB +// "xperia", // xperia Sony Mobile Communications AB "xxx", // xxx ICM Registry LLC "xyz", // xyz XYZ.COM LLC "yachts", // yachts DERYachts, LLC @@ -1524,13 +1681,14 @@ private String chompLeadingDot(String str) { "zara", // zara Industria de Diseño Textil, S.A. (INDITEX, S.A.) "zero", // zero Amazon Registry Services, Inc. "zip", // zip Charleston Road Registry Inc. - "zippo", // zippo Zadco Company +// "zippo", // zippo Zadco Company "zone", // zone Outer Falls, LLC "zuerich", // zuerich Kanton Zürich (Canton of Zurich) }; // WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search private static final String[] COUNTRY_CODE_TLDS = new String[] { + // Taken from Version 2020051000, Last Updated Sun May 10 07:07:01 2020 UTC "ac", // Ascension Island "ad", // Andorra "ae", // United Arab Emirates @@ -1737,6 +1895,7 @@ private String chompLeadingDot(String str) { "sn", // Senegal "so", // Somalia "sr", // Suriname + "ss", // ss National Communication Authority (NCA) "st", // São Tomé and Príncipe "su", // Soviet Union (deprecated) "sv", // El Salvador @@ -1775,7 +1934,10 @@ private String chompLeadingDot(String str) { "vu", // Vanuatu "wf", // Wallis and Futuna "ws", // Samoa (formerly Western Samoa) + "xn--2scrj9c", // ಭಾರತ National Internet eXchange of India "xn--3e0b707e", // 한국 KISA (Korea Internet & Security Agency) + "xn--3hcrj9c", // ଭାରତ National Internet eXchange of India + "xn--45br5cyl", // ভাৰত National Internet eXchange of India "xn--45brj9c", // ভারত National Internet Exchange of India "xn--54b7fta0cc", // বাংলা Posts and Telecommunications Division "xn--80ao21a", // қаз Association of IT Companies of Kazakhstan @@ -1789,7 +1951,9 @@ private String chompLeadingDot(String str) { "xn--fpcrj9c3d", // భారత్ National Internet Exchange of India "xn--fzc2c9e2c", // ලංකා LK Domain Registry "xn--gecrj9c", // ભારત National Internet Exchange of India + "xn--h2breg3eve", // भारतम् National Internet eXchange of India "xn--h2brj9c", // भारत National Internet Exchange of India + "xn--h2brj9c8c", // भारोत National Internet eXchange of India "xn--j1amh", // укр Ukrainian Network Information Centre (UANIC), Inc. "xn--j6w193g", // 香港 Hong Kong Internet Registration Corporation Ltd. "xn--kprw13d", // 台湾 Taiwan Network Information Center (TWNIC) @@ -1799,10 +1963,15 @@ private String chompLeadingDot(String str) { "xn--mgb9awbf", // عمان Telecommunications Regulatory Authority (TRA) "xn--mgba3a4f16a", // ایران Institute for Research in Fundamental Sciences (IPM) "xn--mgbaam7a8h", // امارات Telecommunications Regulatory Authority (TRA) + "xn--mgbah1a3hjkrd", // موريتانيا Université de Nouakchott Al Aasriya + "xn--mgbai9azgqp6j", // پاکستان National Telecommunication Corporation "xn--mgbayh7gpa", // الاردن National Information Technology Center (NITC) + "xn--mgbbh1a", // بارت National Internet eXchange of India "xn--mgbbh1a71e", // بھارت National Internet Exchange of India "xn--mgbc0a9azcg", // المغرب Agence Nationale de Réglementation des Télécommunications (ANRT) + "xn--mgbcpq6gpa1a", // البحرين Telecommunications Regulatory Authority (TRA) "xn--mgberp4a5d4ar", // السعودية Communications and Information Technology Commission + "xn--mgbgu82a", // ڀارت National Internet eXchange of India "xn--mgbpl2fh", // ????? Sudan Internet Society "xn--mgbtx2b", // عراق Communications and Media Commission (CMC) "xn--mgbx4cd0ab", // مليسيا MYNIC Berhad @@ -1812,7 +1981,10 @@ private String chompLeadingDot(String str) { "xn--ogbpf8fl", // سورية National Agency for Network Services (NANS) "xn--p1ai", // рф Coordination Center for TLD RU "xn--pgbs0dh", // تونس Agence Tunisienne d'Internet + "xn--q7ce6a", // ລາວ Lao National Internet Center (LANIC) + "xn--qxa6a", // ευ EURid vzw/asbl "xn--qxam", // ελ ICS-FORTH GR + "xn--rvc1e0am3e", // ഭാരതം National Internet eXchange of India "xn--s9brj9c", // ਭਾਰਤ National Internet Exchange of India "xn--wgbh1c", // مصر National Telecommunication Regulatory Authority - NTRA "xn--wgbl6a", // قطر Communications Regulatory Authority @@ -1846,22 +2018,29 @@ private String chompLeadingDot(String str) { private static boolean inUse = false; /* - * These arrays are mutable, but they don't need to be volatile. - * They can only be updated by the updateTLDOverride method, and any readers must get an instance + * These arrays are mutable. + * They can only be updated by the updateTLDOverride method, and readers must first get an instance * using the getInstance methods which are all (now) synchronised. + * The only other access is via getTLDEntries which is now synchronised. */ // WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search - private static volatile String[] countryCodeTLDsPlus = MemoryReductionUtil.EMPTY_STRING_ARRAY; + private static String[] countryCodeTLDsPlus = MemoryReductionUtil.EMPTY_STRING_ARRAY; + + // WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search + private static String[] genericTLDsPlus = MemoryReductionUtil.EMPTY_STRING_ARRAY; // WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search - private static volatile String[] genericTLDsPlus = MemoryReductionUtil.EMPTY_STRING_ARRAY; + private static String[] countryCodeTLDsMinus = MemoryReductionUtil.EMPTY_STRING_ARRAY; // WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search - private static volatile String[] countryCodeTLDsMinus = MemoryReductionUtil.EMPTY_STRING_ARRAY; + private static String[] genericTLDsMinus = MemoryReductionUtil.EMPTY_STRING_ARRAY; // WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search - private static volatile String[] genericTLDsMinus = MemoryReductionUtil.EMPTY_STRING_ARRAY; + private static String[] localTLDsMinus = MemoryReductionUtil.EMPTY_STRING_ARRAY; + // WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search + private static String[] localTLDsPlus = MemoryReductionUtil.EMPTY_STRING_ARRAY; + /** * enum used by {@link DomainValidator#updateTLDOverride(DomainValidator.ArrayType, String[])} * to determine which override array to update / fetch @@ -1884,17 +2063,37 @@ public enum ArrayType { /** Get a copy of the infrastructure table */ INFRASTRUCTURE_RO, /** Get a copy of the local table */ - LOCAL_RO + LOCAL_RO, + /** + * Update (or get a copy of) the LOCAL_TLDS_PLUS table containing additional local TLDs + * @since 1.7 + */ + LOCAL_PLUS, + /** + * Update (or get a copy of) the LOCAL_TLDS_MINUS table containing deleted local TLDs + * @since 1.7 + */ + LOCAL_MINUS } - // For use by unit test code only - static synchronized void clearTLDOverrides() { - inUse = false; - countryCodeTLDsPlus = MemoryReductionUtil.EMPTY_STRING_ARRAY; - countryCodeTLDsMinus = MemoryReductionUtil.EMPTY_STRING_ARRAY; - genericTLDsPlus = MemoryReductionUtil.EMPTY_STRING_ARRAY; - genericTLDsMinus = MemoryReductionUtil.EMPTY_STRING_ARRAY; + /** + * Used to specify overrides when creating a new class. + * @since 1.7 + */ + public static class Item { + final ArrayType type; + final String[] values; + /** + * + * @param type ArrayType, e.g. GENERIC_PLUS, LOCAL_PLUS + * @param values array of TLDs. Will be lower-cased and sorted + */ + public Item(ArrayType type, String[] values) { + this.type = type; + this.values = values; // no need to copy here + } } + /** * Update one of the TLD override arrays. * This must only be done at program startup, before any instances are accessed using getInstance. @@ -1912,6 +2111,8 @@ static synchronized void clearTLDOverrides() { *
{@code ALLOW_2_SLASHES + NO_FRAGMENTS}
+ * enables both of those options. + * @param domainValidator the DomainValidator to use; must agree with ALLOW_LOCAL_URLS setting + * @since 1.7 + */ + public UrlValidator(String[] schemes, RegexValidator authorityValidator, long options, DomainValidator domainValidator) { this.options = options; + if (domainValidator == null) { + throw new IllegalArgumentException("DomainValidator must not be null"); + } + if (domainValidator.isAllowLocal() != ((options & ALLOW_LOCAL_URLS) > 0)){ + throw new IllegalArgumentException("DomainValidator disagrees with ALLOW_LOCAL_URLS setting"); + } + this.domainValidator = domainValidator; if (isOn(ALLOW_ALL_SCHEMES)) { allowedSchemes = Collections.emptySet(); @@ -306,41 +307,40 @@ public boolean isValid(String value) { return false; } - // Check the whole url address structure - Matcher urlMatcher = URL_PATTERN.matcher(value); - if (!urlMatcher.matches()) { + URI uri; // ensure value is a valid URI + try { + uri = new URI(value); + } catch (URISyntaxException e) { return false; } + // OK, perfom additional validation - String scheme = urlMatcher.group(PARSE_URL_SCHEME); + String scheme = uri.getScheme(); if (!isValidScheme(scheme)) { return false; } - String authority = urlMatcher.group(PARSE_URL_AUTHORITY); - if ("file".equals(scheme)) {// Special case - file: allows an empty authority - if (authority != null) { - if (authority.contains(":")) { // but cannot allow trailing : - return false; - } - } - // drop through to continue validation - } else { // not file: + String authority = uri.getRawAuthority(); + if ("file".equals(scheme) && (authority == null || "".equals(authority))) {// Special case - file: allows an empty authority + return true; // this is a local file - nothing more to do here + } else if ("file".equals(scheme) && authority != null && authority.contains(":")) { + return false; + } else { // Validate the authority if (!isValidAuthority(authority)) { return false; } } - if (!isValidPath(urlMatcher.group(PARSE_URL_PATH))) { + if (!isValidPath(uri.getRawPath())) { return false; } - if (!isValidQuery(urlMatcher.group(PARSE_URL_QUERY))) { + if (!isValidQuery(uri.getRawQuery())) { return false; } - if (!isValidFragment(urlMatcher.group(PARSE_URL_FRAGMENT))) { + if (!isValidFragment(uri.getRawFragment())) { return false; } @@ -361,7 +361,6 @@ protected boolean isValidScheme(String scheme) { return false; } - // TODO could be removed if external schemes were checked in the ctor before being stored if (!SCHEME_PATTERN.matcher(scheme).matches()) { return false; } @@ -411,8 +410,7 @@ protected boolean isValidAuthority(String authority) { String hostLocation = authorityMatcher.group(PARSE_AUTHORITY_HOST_IP); // check if authority is hostname or IP address: // try a hostname first since that's much more likely - DomainValidator domainValidator = DomainValidator.getInstance(isOn(ALLOW_LOCAL_URLS)); - if (!domainValidator.isValid(hostLocation)) { + if (!this.domainValidator.isValid(hostLocation)) { // try an IPv4 address InetAddressValidator inetAddressValidator = InetAddressValidator.getInstance(); if (!inetAddressValidator.isValidInet4Address(hostLocation)) { @@ -456,7 +454,8 @@ protected boolean isValidPath(String path) { } try { - URI uri = new URI(null,null,path,null); + // Don't omit host otherwise leading path may be taken as host if it starts with // + URI uri = new URI(null,"localhost",path,null); String norm = uri.normalize().getPath(); if (norm.startsWith("/../") // Trying to go via the parent dir || norm.equals("/..")) { // Trying to go to the parent dir @@ -531,6 +530,19 @@ private boolean isOn(long flag) { return (options & flag) > 0; } + /** + * Tests whether the given flag is on. If the flag is not a power of 2 + * (e.g. 3) this tests whether the combination of flags is on. + * + * @param flag Flag value to check. + * @param options what to check + * + * @return whether the specified flag value is on. + */ + private static boolean isOn(long flag, long options) { + return (options & flag) > 0; + } + /** * Tests whether the given flag is off. If the flag is not a power of 2 * (ie. 3) this tests whether the combination of flags is off. @@ -542,9 +554,4 @@ private boolean isOn(long flag) { private boolean isOff(long flag) { return (options & flag) == 0; } - - // Unit test access to pattern matcher - Matcher matchURL(String value) { - return URL_PATTERN.matcher(value); - } } diff --git a/core/src/test/java/jenkins/org/apache/commons/validator/ResultPair.java b/core/src/test/java/jenkins/org/apache/commons/validator/ResultPair.java new file mode 100644 index 000000000000..f31c35bf1c84 --- /dev/null +++ b/core/src/test/java/jenkins/org/apache/commons/validator/ResultPair.java @@ -0,0 +1,32 @@ +/* + * 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 jenkins.org.apache.commons.validator; + +/** + * Groups tests and expected results. + * + * @version $Revision$ + */ + public class ResultPair { + public final String item; + public final boolean valid; + + public ResultPair(String item, boolean valid) { + this.item = item; + this.valid = valid; //Whether the individual part of url is valid. + } + } diff --git a/core/src/test/java/jenkins/org/apache/commons/validator/routines/DomainValidatorTest.java b/core/src/test/java/jenkins/org/apache/commons/validator/routines/DomainValidatorTest.java new file mode 100644 index 000000000000..2cdd2c5880db --- /dev/null +++ b/core/src/test/java/jenkins/org/apache/commons/validator/routines/DomainValidatorTest.java @@ -0,0 +1,639 @@ +/* + * 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 jenkins.org.apache.commons.validator.routines; + +import java.io.BufferedReader; +import java.io.Closeable; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.net.HttpURLConnection; +import java.net.IDN; +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import jenkins.org.apache.commons.validator.routines.DomainValidator.ArrayType; +import junit.framework.TestCase; + +/** + * Tests for the DomainValidator. + * + * @version $Revision$ + */ +public class DomainValidatorTest extends TestCase { + + private DomainValidator validator; + + @Override + public void setUp() { + validator = DomainValidator.getInstance(); + } + + public void testValidDomains() { + assertTrue("apache.org should validate", validator.isValid("apache.org")); + assertTrue("www.google.com should validate", validator.isValid("www.google.com")); + + assertTrue("test-domain.com should validate", validator.isValid("test-domain.com")); + assertTrue("test---domain.com should validate", validator.isValid("test---domain.com")); + assertTrue("test-d-o-m-ain.com should validate", validator.isValid("test-d-o-m-ain.com")); + assertTrue("two-letter domain label should validate", validator.isValid("as.uk")); + + assertTrue("case-insensitive ApAchE.Org should validate", validator.isValid("ApAchE.Org")); + + assertTrue("single-character domain label should validate", validator.isValid("z.com")); + + assertTrue("i.have.an-example.domain.name should validate", validator.isValid("i.have.an-example.domain.name")); + } + + public void testInvalidDomains() { + assertFalse("bare TLD .org shouldn't validate", validator.isValid(".org")); + assertFalse("domain name with spaces shouldn't validate", validator.isValid(" apache.org ")); + assertFalse("domain name containing spaces shouldn't validate", validator.isValid("apa che.org")); + assertFalse("domain name starting with dash shouldn't validate", validator.isValid("-testdomain.name")); + assertFalse("domain name ending with dash shouldn't validate", validator.isValid("testdomain-.name")); + assertFalse("domain name starting with multiple dashes shouldn't validate", validator.isValid("---c.com")); + assertFalse("domain name ending with multiple dashes shouldn't validate", validator.isValid("c--.com")); + assertFalse("domain name with invalid TLD shouldn't validate", validator.isValid("apache.rog")); + + assertFalse("URL shouldn't validate", validator.isValid("http://www.apache.org")); + assertFalse("Empty string shouldn't validate as domain name", validator.isValid(" ")); + assertFalse("Null shouldn't validate as domain name", validator.isValid(null)); + } + + public void testTopLevelDomains() { + // infrastructure TLDs + assertTrue(".arpa should validate as iTLD", validator.isValidInfrastructureTld(".arpa")); + assertFalse(".com shouldn't validate as iTLD", validator.isValidInfrastructureTld(".com")); + + // generic TLDs + assertTrue(".name should validate as gTLD", validator.isValidGenericTld(".name")); + assertFalse(".us shouldn't validate as gTLD", validator.isValidGenericTld(".us")); + + // country code TLDs + assertTrue(".uk should validate as ccTLD", validator.isValidCountryCodeTld(".uk")); + assertFalse(".org shouldn't validate as ccTLD", validator.isValidCountryCodeTld(".org")); + + // case-insensitive + assertTrue(".COM should validate as TLD", validator.isValidTld(".COM")); + assertTrue(".BiZ should validate as TLD", validator.isValidTld(".BiZ")); + + // corner cases + assertFalse("invalid TLD shouldn't validate", validator.isValid(".nope")); // TODO this is not guaranteed invalid forever + assertFalse("empty string shouldn't validate as TLD", validator.isValid("")); + assertFalse("null shouldn't validate as TLD", validator.isValid(null)); + } + + public void testAllowLocal() { + DomainValidator noLocal = DomainValidator.getInstance(false); + DomainValidator allowLocal = DomainValidator.getInstance(true); + + // Default is false, and should use singletons + assertEquals(noLocal, validator); + + // Default won't allow local + assertFalse("localhost.localdomain should validate", noLocal.isValid("localhost.localdomain")); + assertFalse("localhost should validate", noLocal.isValid("localhost")); + + // But it may be requested + assertTrue("localhost.localdomain should validate", allowLocal.isValid("localhost.localdomain")); + assertTrue("localhost should validate", allowLocal.isValid("localhost")); + assertTrue("hostname should validate", allowLocal.isValid("hostname")); + assertTrue("machinename should validate", allowLocal.isValid("machinename")); + + // Check the localhost one with a few others + assertTrue("apache.org should validate", allowLocal.isValid("apache.org")); + assertFalse("domain name with spaces shouldn't validate", allowLocal.isValid(" apache.org ")); + } + + public void testIDN() { + assertTrue("b\u00fccher.ch in IDN should validate", validator.isValid("www.xn--bcher-kva.ch")); + } + + public void testIDNJava6OrLater() { + String version = System.getProperty("java.version"); + if (version.compareTo("1.6") < 0) { + System.out.println("Cannot run Unicode IDN tests"); + return; // Cannot run the test + } // xn--d1abbgf6aiiy.xn--p1ai http://президент.рф + assertTrue("b\u00fccher.ch should validate", validator.isValid("www.b\u00fccher.ch")); + assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("xn--d1abbgf6aiiy.xn--p1ai")); + assertTrue("президент.рф should validate", validator.isValid("президент.рф")); + assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("www.\uFFFD.ch")); + } + + // RFC2396: domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum + public void testRFC2396domainlabel() { // use fixed valid TLD + assertTrue("a.ch should validate", validator.isValid("a.ch")); + assertTrue("9.ch should validate", validator.isValid("9.ch")); + assertTrue("az.ch should validate", validator.isValid("az.ch")); + assertTrue("09.ch should validate", validator.isValid("09.ch")); + assertTrue("9-1.ch should validate", validator.isValid("9-1.ch")); + assertFalse("91-.ch should not validate", validator.isValid("91-.ch")); + assertFalse("-.ch should not validate", validator.isValid("-.ch")); + } + + // RFC2396 toplabel = alpha | alpha *( alphanum | "-" ) alphanum + public void testRFC2396toplabel() { + // These tests use non-existent TLDs so currently need to use a package protected method + assertTrue("a.c (alpha) should validate", validator.isValidDomainSyntax("a.c")); + assertTrue("a.cc (alpha alpha) should validate", validator.isValidDomainSyntax("a.cc")); + assertTrue("a.c9 (alpha alphanum) should validate", validator.isValidDomainSyntax("a.c9")); + assertTrue("a.c-9 (alpha - alphanum) should validate", validator.isValidDomainSyntax("a.c-9")); + assertTrue("a.c-z (alpha - alpha) should validate", validator.isValidDomainSyntax("a.c-z")); + + assertFalse("a.9c (alphanum alpha) should fail", validator.isValidDomainSyntax("a.9c")); + assertFalse("a.c- (alpha -) should fail", validator.isValidDomainSyntax("a.c-")); + assertFalse("a.- (-) should fail", validator.isValidDomainSyntax("a.-")); + assertFalse("a.-9 (- alphanum) should fail", validator.isValidDomainSyntax("a.-9")); + } + + public void testDomainNoDots() {// rfc1123 + assertTrue("a (alpha) should validate", validator.isValidDomainSyntax("a")); + assertTrue("9 (alphanum) should validate", validator.isValidDomainSyntax("9")); + assertTrue("c-z (alpha - alpha) should validate", validator.isValidDomainSyntax("c-z")); + + assertFalse("c- (alpha -) should fail", validator.isValidDomainSyntax("c-")); + assertFalse("-c (- alpha) should fail", validator.isValidDomainSyntax("-c")); + assertFalse("- (-) should fail", validator.isValidDomainSyntax("-")); + } + + public void testValidator297() { + assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("xn--d1abbgf6aiiy.xn--p1ai")); // This uses a valid TLD + } + + // labels are a max of 63 chars and domains 253 + public void testValidator306() { + final String longString = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789A"; + assertEquals(63, longString.length()); // 26 * 2 + 11 + + assertTrue("63 chars label should validate", validator.isValidDomainSyntax(longString+".com")); + assertFalse("64 chars label should fail", validator.isValidDomainSyntax(longString+"x.com")); + + assertTrue("63 chars TLD should validate", validator.isValidDomainSyntax("test."+longString)); + assertFalse("64 chars TLD should fail", validator.isValidDomainSyntax("test.x"+longString)); + + final String longDomain = + longString + + "." + longString + + "." + longString + + "." + longString.substring(0,61) + ; + assertEquals(253, longDomain.length()); + assertTrue("253 chars domain should validate", validator.isValidDomainSyntax(longDomain)); + assertFalse("254 chars domain should fail", validator.isValidDomainSyntax(longDomain+"x")); + } + + // Check that IDN.toASCII behaves as it should (when wrapped by DomainValidator.unicodeToASCII) + // Tests show that method incorrectly trims a trailing "." character + public void testUnicodeToASCII() { + String[] asciidots = { + "", + ",", + ".", // fails IDN.toASCII, but should pass wrapped version + "a.", // ditto + "a.b", + "a..b", + "a...b", + ".a", + "..a", + }; + for(String s : asciidots) { + assertEquals(s,DomainValidator.unicodeToASCII(s)); + } + // RFC3490 3.1. 1) +// Whenever dots are used as label separators, the following +// characters MUST be recognized as dots: U+002E (full stop), U+3002 +// (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61 +// (halfwidth ideographic full stop). + final String[][] otherDots = { + {"b\u3002", "b.",}, + {"b\uFF0E", "b.",}, + {"b\uFF61", "b.",}, + {"\u3002", ".",}, + {"\uFF0E", ".",}, + {"\uFF61", ".",}, + }; + for(String[] s : otherDots) { + assertEquals(s[1],DomainValidator.unicodeToASCII(s[0])); + } + } + + // Check if IDN.toASCII is broken or not + public void testIsIDNtoASCIIBroken() { + System.out.println(">>DomainValidatorTest.testIsIDNtoASCIIBroken()"); + final String input = "."; + final boolean ok = input.equals(IDN.toASCII(input)); + System.out.println("IDN.toASCII is " + (ok? "OK" : "BROKEN")); + String[] props = { + "java.version", // Java Runtime Environment version + "java.vendor", // Java Runtime Environment vendor + "java.vm.specification.version", // Java Virtual Machine specification version + "java.vm.specification.vendor", // Java Virtual Machine specification vendor + "java.vm.specification.name", // Java Virtual Machine specification name + "java.vm.version", // Java Virtual Machine implementation version + "java.vm.vendor", // Java Virtual Machine implementation vendor + "java.vm.name", // Java Virtual Machine implementation name + "java.specification.version", // Java Runtime Environment specification version + "java.specification.vendor", // Java Runtime Environment specification vendor + "java.specification.name", // Java Runtime Environment specification name + "java.class.version", // Java class format version number + }; + for(String t : props) { + System.out.println(t + "=" + System.getProperty(t)); + } + System.out.println("<These tests were ported from a + * Perl script.
+ * + */ + public void testIPv6() { + // The original Perl script contained a lot of duplicate tests. + // I removed the duplicates I noticed, but there may be more. + assertFalse("IPV6 empty string should be invalid", validator.isValidInet6Address(""));// empty string + assertTrue("IPV6 ::1 should be valid", validator.isValidInet6Address("::1"));// loopback, compressed, non-routable + assertTrue("IPV6 :: should be valid", validator.isValidInet6Address("::"));// unspecified, compressed, non-routable + assertTrue("IPV6 0:0:0:0:0:0:0:1 should be valid", validator.isValidInet6Address("0:0:0:0:0:0:0:1"));// loopback, full + assertTrue("IPV6 0:0:0:0:0:0:0:0 should be valid", validator.isValidInet6Address("0:0:0:0:0:0:0:0"));// unspecified, full + assertTrue("IPV6 2001:DB8:0:0:8:800:200C:417A should be valid", validator.isValidInet6Address("2001:DB8:0:0:8:800:200C:417A"));// unicast, full + assertTrue("IPV6 FF01:0:0:0:0:0:0:101 should be valid", validator.isValidInet6Address("FF01:0:0:0:0:0:0:101"));// multicast, full + assertTrue("IPV6 2001:DB8::8:800:200C:417A should be valid", validator.isValidInet6Address("2001:DB8::8:800:200C:417A"));// unicast, compressed + assertTrue("IPV6 FF01::101 should be valid", validator.isValidInet6Address("FF01::101"));// multicast, compressed + assertFalse("IPV6 2001:DB8:0:0:8:800:200C:417A:221 should be invalid", validator.isValidInet6Address("2001:DB8:0:0:8:800:200C:417A:221"));// unicast, full + assertFalse("IPV6 FF01::101::2 should be invalid", validator.isValidInet6Address("FF01::101::2"));// multicast, compressed + assertTrue("IPV6 fe80::217:f2ff:fe07:ed62 should be valid", validator.isValidInet6Address("fe80::217:f2ff:fe07:ed62")); + assertTrue("IPV6 2001:0000:1234:0000:0000:C1C0:ABCD:0876 should be valid", validator.isValidInet6Address("2001:0000:1234:0000:0000:C1C0:ABCD:0876")); + assertTrue("IPV6 3ffe:0b00:0000:0000:0001:0000:0000:000a should be valid", validator.isValidInet6Address("3ffe:0b00:0000:0000:0001:0000:0000:000a")); + assertTrue("IPV6 FF02:0000:0000:0000:0000:0000:0000:0001 should be valid", validator.isValidInet6Address("FF02:0000:0000:0000:0000:0000:0000:0001")); + assertTrue("IPV6 0000:0000:0000:0000:0000:0000:0000:0001 should be valid", validator.isValidInet6Address("0000:0000:0000:0000:0000:0000:0000:0001")); + assertTrue("IPV6 0000:0000:0000:0000:0000:0000:0000:0000 should be valid", validator.isValidInet6Address("0000:0000:0000:0000:0000:0000:0000:0000")); + assertFalse("IPV6 02001:0000:1234:0000:0000:C1C0:ABCD:0876 should be invalid", validator.isValidInet6Address("02001:0000:1234:0000:0000:C1C0:ABCD:0876")); // extra 0 not allowed! + assertFalse("IPV6 2001:0000:1234:0000:00001:C1C0:ABCD:0876 should be invalid", validator.isValidInet6Address("2001:0000:1234:0000:00001:C1C0:ABCD:0876")); // extra 0 not allowed! + assertFalse("IPV6 2001:0000:1234:0000:0000:C1C0:ABCD:0876 0 should be invalid", validator.isValidInet6Address("2001:0000:1234:0000:0000:C1C0:ABCD:0876 0")); // junk after valid address + assertFalse("IPV6 2001:0000:1234: 0000:0000:C1C0:ABCD:0876 should be invalid", validator.isValidInet6Address("2001:0000:1234: 0000:0000:C1C0:ABCD:0876")); // internal space + assertFalse("IPV6 3ffe:0b00:0000:0001:0000:0000:000a should be invalid", validator.isValidInet6Address("3ffe:0b00:0000:0001:0000:0000:000a")); // seven segments + assertFalse("IPV6 FF02:0000:0000:0000:0000:0000:0000:0000:0001 should be invalid", validator.isValidInet6Address("FF02:0000:0000:0000:0000:0000:0000:0000:0001")); // nine segments + assertFalse("IPV6 3ffe:b00::1::a should be invalid", validator.isValidInet6Address("3ffe:b00::1::a")); // double "::" + assertFalse("IPV6 ::1111:2222:3333:4444:5555:6666:: should be invalid", validator.isValidInet6Address("::1111:2222:3333:4444:5555:6666::")); // double "::" + assertTrue("IPV6 2::10 should be valid", validator.isValidInet6Address("2::10")); + assertTrue("IPV6 ff02::1 should be valid", validator.isValidInet6Address("ff02::1")); + assertTrue("IPV6 fe80:: should be valid", validator.isValidInet6Address("fe80::")); + assertTrue("IPV6 2002:: should be valid", validator.isValidInet6Address("2002::")); + assertTrue("IPV6 2001:db8:: should be valid", validator.isValidInet6Address("2001:db8::")); + assertTrue("IPV6 2001:0db8:1234:: should be valid", validator.isValidInet6Address("2001:0db8:1234::")); + assertTrue("IPV6 ::ffff:0:0 should be valid", validator.isValidInet6Address("::ffff:0:0")); + assertTrue("IPV6 1:2:3:4:5:6:7:8 should be valid", validator.isValidInet6Address("1:2:3:4:5:6:7:8")); + assertTrue("IPV6 1:2:3:4:5:6::8 should be valid", validator.isValidInet6Address("1:2:3:4:5:6::8")); + assertTrue("IPV6 1:2:3:4:5::8 should be valid", validator.isValidInet6Address("1:2:3:4:5::8")); + assertTrue("IPV6 1:2:3:4::8 should be valid", validator.isValidInet6Address("1:2:3:4::8")); + assertTrue("IPV6 1:2:3::8 should be valid", validator.isValidInet6Address("1:2:3::8")); + assertTrue("IPV6 1:2::8 should be valid", validator.isValidInet6Address("1:2::8")); + assertTrue("IPV6 1::8 should be valid", validator.isValidInet6Address("1::8")); + assertTrue("IPV6 1::2:3:4:5:6:7 should be valid", validator.isValidInet6Address("1::2:3:4:5:6:7")); + assertTrue("IPV6 1::2:3:4:5:6 should be valid", validator.isValidInet6Address("1::2:3:4:5:6")); + assertTrue("IPV6 1::2:3:4:5 should be valid", validator.isValidInet6Address("1::2:3:4:5")); + assertTrue("IPV6 1::2:3:4 should be valid", validator.isValidInet6Address("1::2:3:4")); + assertTrue("IPV6 1::2:3 should be valid", validator.isValidInet6Address("1::2:3")); + assertTrue("IPV6 ::2:3:4:5:6:7:8 should be valid", validator.isValidInet6Address("::2:3:4:5:6:7:8")); + assertTrue("IPV6 ::2:3:4:5:6:7 should be valid", validator.isValidInet6Address("::2:3:4:5:6:7")); + assertTrue("IPV6 ::2:3:4:5:6 should be valid", validator.isValidInet6Address("::2:3:4:5:6")); + assertTrue("IPV6 ::2:3:4:5 should be valid", validator.isValidInet6Address("::2:3:4:5")); + assertTrue("IPV6 ::2:3:4 should be valid", validator.isValidInet6Address("::2:3:4")); + assertTrue("IPV6 ::2:3 should be valid", validator.isValidInet6Address("::2:3")); + assertTrue("IPV6 ::8 should be valid", validator.isValidInet6Address("::8")); + assertTrue("IPV6 1:2:3:4:5:6:: should be valid", validator.isValidInet6Address("1:2:3:4:5:6::")); + assertTrue("IPV6 1:2:3:4:5:: should be valid", validator.isValidInet6Address("1:2:3:4:5::")); + assertTrue("IPV6 1:2:3:4:: should be valid", validator.isValidInet6Address("1:2:3:4::")); + assertTrue("IPV6 1:2:3:: should be valid", validator.isValidInet6Address("1:2:3::")); + assertTrue("IPV6 1:2:: should be valid", validator.isValidInet6Address("1:2::")); + assertTrue("IPV6 1:: should be valid", validator.isValidInet6Address("1::")); + assertTrue("IPV6 1:2:3:4:5::7:8 should be valid", validator.isValidInet6Address("1:2:3:4:5::7:8")); + assertFalse("IPV6 1:2:3::4:5::7:8 should be invalid", validator.isValidInet6Address("1:2:3::4:5::7:8")); // Double "::" + assertFalse("IPV6 12345::6:7:8 should be invalid", validator.isValidInet6Address("12345::6:7:8")); + assertTrue("IPV6 1:2:3:4::7:8 should be valid", validator.isValidInet6Address("1:2:3:4::7:8")); + assertTrue("IPV6 1:2:3::7:8 should be valid", validator.isValidInet6Address("1:2:3::7:8")); + assertTrue("IPV6 1:2::7:8 should be valid", validator.isValidInet6Address("1:2::7:8")); + assertTrue("IPV6 1::7:8 should be valid", validator.isValidInet6Address("1::7:8")); + // IPv4 addresses as dotted-quads + assertTrue("IPV6 1:2:3:4:5:6:1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3:4:5:6:1.2.3.4")); + assertTrue("IPV6 1:2:3:4:5::1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3:4:5::1.2.3.4")); + assertTrue("IPV6 1:2:3:4::1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3:4::1.2.3.4")); + assertTrue("IPV6 1:2:3::1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3::1.2.3.4")); + assertTrue("IPV6 1:2::1.2.3.4 should be valid", validator.isValidInet6Address("1:2::1.2.3.4")); + assertTrue("IPV6 1::1.2.3.4 should be valid", validator.isValidInet6Address("1::1.2.3.4")); + assertTrue("IPV6 1:2:3:4::5:1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3:4::5:1.2.3.4")); + assertTrue("IPV6 1:2:3::5:1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3::5:1.2.3.4")); + assertTrue("IPV6 1:2::5:1.2.3.4 should be valid", validator.isValidInet6Address("1:2::5:1.2.3.4")); + assertTrue("IPV6 1::5:1.2.3.4 should be valid", validator.isValidInet6Address("1::5:1.2.3.4")); + assertTrue("IPV6 1::5:11.22.33.44 should be valid", validator.isValidInet6Address("1::5:11.22.33.44")); + assertFalse("IPV6 1::5:400.2.3.4 should be invalid", validator.isValidInet6Address("1::5:400.2.3.4")); + assertFalse("IPV6 1::5:260.2.3.4 should be invalid", validator.isValidInet6Address("1::5:260.2.3.4")); + assertFalse("IPV6 1::5:256.2.3.4 should be invalid", validator.isValidInet6Address("1::5:256.2.3.4")); + assertFalse("IPV6 1::5:1.256.3.4 should be invalid", validator.isValidInet6Address("1::5:1.256.3.4")); + assertFalse("IPV6 1::5:1.2.256.4 should be invalid", validator.isValidInet6Address("1::5:1.2.256.4")); + assertFalse("IPV6 1::5:1.2.3.256 should be invalid", validator.isValidInet6Address("1::5:1.2.3.256")); + assertFalse("IPV6 1::5:300.2.3.4 should be invalid", validator.isValidInet6Address("1::5:300.2.3.4")); + assertFalse("IPV6 1::5:1.300.3.4 should be invalid", validator.isValidInet6Address("1::5:1.300.3.4")); + assertFalse("IPV6 1::5:1.2.300.4 should be invalid", validator.isValidInet6Address("1::5:1.2.300.4")); + assertFalse("IPV6 1::5:1.2.3.300 should be invalid", validator.isValidInet6Address("1::5:1.2.3.300")); + assertFalse("IPV6 1::5:900.2.3.4 should be invalid", validator.isValidInet6Address("1::5:900.2.3.4")); + assertFalse("IPV6 1::5:1.900.3.4 should be invalid", validator.isValidInet6Address("1::5:1.900.3.4")); + assertFalse("IPV6 1::5:1.2.900.4 should be invalid", validator.isValidInet6Address("1::5:1.2.900.4")); + assertFalse("IPV6 1::5:1.2.3.900 should be invalid", validator.isValidInet6Address("1::5:1.2.3.900")); + assertFalse("IPV6 1::5:300.300.300.300 should be invalid", validator.isValidInet6Address("1::5:300.300.300.300")); + assertFalse("IPV6 1::5:3000.30.30.30 should be invalid", validator.isValidInet6Address("1::5:3000.30.30.30")); + assertFalse("IPV6 1::400.2.3.4 should be invalid", validator.isValidInet6Address("1::400.2.3.4")); + assertFalse("IPV6 1::260.2.3.4 should be invalid", validator.isValidInet6Address("1::260.2.3.4")); + assertFalse("IPV6 1::256.2.3.4 should be invalid", validator.isValidInet6Address("1::256.2.3.4")); + assertFalse("IPV6 1::1.256.3.4 should be invalid", validator.isValidInet6Address("1::1.256.3.4")); + assertFalse("IPV6 1::1.2.256.4 should be invalid", validator.isValidInet6Address("1::1.2.256.4")); + assertFalse("IPV6 1::1.2.3.256 should be invalid", validator.isValidInet6Address("1::1.2.3.256")); + assertFalse("IPV6 1::300.2.3.4 should be invalid", validator.isValidInet6Address("1::300.2.3.4")); + assertFalse("IPV6 1::1.300.3.4 should be invalid", validator.isValidInet6Address("1::1.300.3.4")); + assertFalse("IPV6 1::1.2.300.4 should be invalid", validator.isValidInet6Address("1::1.2.300.4")); + assertFalse("IPV6 1::1.2.3.300 should be invalid", validator.isValidInet6Address("1::1.2.3.300")); + assertFalse("IPV6 1::900.2.3.4 should be invalid", validator.isValidInet6Address("1::900.2.3.4")); + assertFalse("IPV6 1::1.900.3.4 should be invalid", validator.isValidInet6Address("1::1.900.3.4")); + assertFalse("IPV6 1::1.2.900.4 should be invalid", validator.isValidInet6Address("1::1.2.900.4")); + assertFalse("IPV6 1::1.2.3.900 should be invalid", validator.isValidInet6Address("1::1.2.3.900")); + assertFalse("IPV6 1::300.300.300.300 should be invalid", validator.isValidInet6Address("1::300.300.300.300")); + assertFalse("IPV6 1::3000.30.30.30 should be invalid", validator.isValidInet6Address("1::3000.30.30.30")); + assertFalse("IPV6 ::400.2.3.4 should be invalid", validator.isValidInet6Address("::400.2.3.4")); + assertFalse("IPV6 ::260.2.3.4 should be invalid", validator.isValidInet6Address("::260.2.3.4")); + assertFalse("IPV6 ::256.2.3.4 should be invalid", validator.isValidInet6Address("::256.2.3.4")); + assertFalse("IPV6 ::1.256.3.4 should be invalid", validator.isValidInet6Address("::1.256.3.4")); + assertFalse("IPV6 ::1.2.256.4 should be invalid", validator.isValidInet6Address("::1.2.256.4")); + assertFalse("IPV6 ::1.2.3.256 should be invalid", validator.isValidInet6Address("::1.2.3.256")); + assertFalse("IPV6 ::300.2.3.4 should be invalid", validator.isValidInet6Address("::300.2.3.4")); + assertFalse("IPV6 ::1.300.3.4 should be invalid", validator.isValidInet6Address("::1.300.3.4")); + assertFalse("IPV6 ::1.2.300.4 should be invalid", validator.isValidInet6Address("::1.2.300.4")); + assertFalse("IPV6 ::1.2.3.300 should be invalid", validator.isValidInet6Address("::1.2.3.300")); + assertFalse("IPV6 ::900.2.3.4 should be invalid", validator.isValidInet6Address("::900.2.3.4")); + assertFalse("IPV6 ::1.900.3.4 should be invalid", validator.isValidInet6Address("::1.900.3.4")); + assertFalse("IPV6 ::1.2.900.4 should be invalid", validator.isValidInet6Address("::1.2.900.4")); + assertFalse("IPV6 ::1.2.3.900 should be invalid", validator.isValidInet6Address("::1.2.3.900")); + assertFalse("IPV6 ::300.300.300.300 should be invalid", validator.isValidInet6Address("::300.300.300.300")); + assertFalse("IPV6 ::3000.30.30.30 should be invalid", validator.isValidInet6Address("::3000.30.30.30")); + assertTrue("IPV6 fe80::217:f2ff:254.7.237.98 should be valid", validator.isValidInet6Address("fe80::217:f2ff:254.7.237.98")); + assertTrue("IPV6 ::ffff:192.168.1.26 should be valid", validator.isValidInet6Address("::ffff:192.168.1.26")); + assertFalse("IPV6 2001:1:1:1:1:1:255Z255X255Y255 should be invalid", validator.isValidInet6Address("2001:1:1:1:1:1:255Z255X255Y255")); // garbage instead of "." in IPv4 + assertFalse("IPV6 ::ffff:192x168.1.26 should be invalid", validator.isValidInet6Address("::ffff:192x168.1.26")); // ditto + assertTrue("IPV6 ::ffff:192.168.1.1 should be valid", validator.isValidInet6Address("::ffff:192.168.1.1")); + assertTrue("IPV6 0:0:0:0:0:0:13.1.68.3 should be valid", validator.isValidInet6Address("0:0:0:0:0:0:13.1.68.3"));// IPv4-compatible IPv6 address, full, deprecated + assertTrue("IPV6 0:0:0:0:0:FFFF:129.144.52.38 should be valid", validator.isValidInet6Address("0:0:0:0:0:FFFF:129.144.52.38"));// IPv4-mapped IPv6 address, full + assertTrue("IPV6 ::13.1.68.3 should be valid", validator.isValidInet6Address("::13.1.68.3"));// IPv4-compatible IPv6 address, compressed, deprecated + assertTrue("IPV6 ::FFFF:129.144.52.38 should be valid", validator.isValidInet6Address("::FFFF:129.144.52.38"));// IPv4-mapped IPv6 address, compressed + assertTrue("IPV6 fe80:0:0:0:204:61ff:254.157.241.86 should be valid", validator.isValidInet6Address("fe80:0:0:0:204:61ff:254.157.241.86")); + assertTrue("IPV6 fe80::204:61ff:254.157.241.86 should be valid", validator.isValidInet6Address("fe80::204:61ff:254.157.241.86")); + assertTrue("IPV6 ::ffff:12.34.56.78 should be valid", validator.isValidInet6Address("::ffff:12.34.56.78")); + assertFalse("IPV6 ::ffff:2.3.4 should be invalid", validator.isValidInet6Address("::ffff:2.3.4")); + assertFalse("IPV6 ::ffff:257.1.2.3 should be invalid", validator.isValidInet6Address("::ffff:257.1.2.3")); + assertFalse("IPV6 1.2.3.4 should be invalid", validator.isValidInet6Address("1.2.3.4")); + assertFalse("IPV6 1.2.3.4:1111:2222:3333:4444::5555 should be invalid", validator.isValidInet6Address("1.2.3.4:1111:2222:3333:4444::5555")); + assertFalse("IPV6 1.2.3.4:1111:2222:3333::5555 should be invalid", validator.isValidInet6Address("1.2.3.4:1111:2222:3333::5555")); + assertFalse("IPV6 1.2.3.4:1111:2222::5555 should be invalid", validator.isValidInet6Address("1.2.3.4:1111:2222::5555")); + assertFalse("IPV6 1.2.3.4:1111::5555 should be invalid", validator.isValidInet6Address("1.2.3.4:1111::5555")); + assertFalse("IPV6 1.2.3.4::5555 should be invalid", validator.isValidInet6Address("1.2.3.4::5555")); + assertFalse("IPV6 1.2.3.4:: should be invalid", validator.isValidInet6Address("1.2.3.4::")); + // Testing IPv4 addresses represented as dotted-quads + // Leading zeroes in IPv4 addresses not allowed: some systems treat the leading "0" in ".086" as the start of an octal number + // Update: The BNF in RFC-3986 explicitly defines the dec-octet (for IPv4 addresses) not to have a leading zero + assertFalse("IPV6 fe80:0000:0000:0000:0204:61ff:254.157.241.086 should be invalid", validator.isValidInet6Address("fe80:0000:0000:0000:0204:61ff:254.157.241.086")); + assertTrue("IPV6 ::ffff:192.0.2.128 should be valid", validator.isValidInet6Address("::ffff:192.0.2.128")); // but this is OK, since there's a single digit + assertFalse("IPV6 XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4 should be invalid", validator.isValidInet6Address("XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:00.00.00.00 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:00.00.00.00")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:000.000.000.000 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:000.000.000.000")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:256.256.256.256 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:256.256.256.256")); + assertTrue("IPV6 fe80:0000:0000:0000:0204:61ff:fe9d:f156 should be valid", validator.isValidInet6Address("fe80:0000:0000:0000:0204:61ff:fe9d:f156")); + assertTrue("IPV6 fe80:0:0:0:204:61ff:fe9d:f156 should be valid", validator.isValidInet6Address("fe80:0:0:0:204:61ff:fe9d:f156")); + assertTrue("IPV6 fe80::204:61ff:fe9d:f156 should be valid", validator.isValidInet6Address("fe80::204:61ff:fe9d:f156")); + assertFalse("IPV6 : should be invalid", validator.isValidInet6Address(":")); + assertTrue("IPV6 ::ffff:c000:280 should be valid", validator.isValidInet6Address("::ffff:c000:280")); + assertFalse("IPV6 1111:2222:3333:4444::5555: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::5555:")); + assertFalse("IPV6 1111:2222:3333::5555: should be invalid", validator.isValidInet6Address("1111:2222:3333::5555:")); + assertFalse("IPV6 1111:2222::5555: should be invalid", validator.isValidInet6Address("1111:2222::5555:")); + assertFalse("IPV6 1111::5555: should be invalid", validator.isValidInet6Address("1111::5555:")); + assertFalse("IPV6 ::5555: should be invalid", validator.isValidInet6Address("::5555:")); + assertFalse("IPV6 ::: should be invalid", validator.isValidInet6Address(":::")); + assertFalse("IPV6 1111: should be invalid", validator.isValidInet6Address("1111:")); + assertFalse("IPV6 :1111:2222:3333:4444::5555 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::5555")); + assertFalse("IPV6 :1111:2222:3333::5555 should be invalid", validator.isValidInet6Address(":1111:2222:3333::5555")); + assertFalse("IPV6 :1111:2222::5555 should be invalid", validator.isValidInet6Address(":1111:2222::5555")); + assertFalse("IPV6 :1111::5555 should be invalid", validator.isValidInet6Address(":1111::5555")); + assertFalse("IPV6 :::5555 should be invalid", validator.isValidInet6Address(":::5555")); + assertTrue("IPV6 2001:0db8:85a3:0000:0000:8a2e:0370:7334 should be valid", validator.isValidInet6Address("2001:0db8:85a3:0000:0000:8a2e:0370:7334")); + assertTrue("IPV6 2001:db8:85a3:0:0:8a2e:370:7334 should be valid", validator.isValidInet6Address("2001:db8:85a3:0:0:8a2e:370:7334")); + assertTrue("IPV6 2001:db8:85a3::8a2e:370:7334 should be valid", validator.isValidInet6Address("2001:db8:85a3::8a2e:370:7334")); + assertTrue("IPV6 2001:0db8:0000:0000:0000:0000:1428:57ab should be valid", validator.isValidInet6Address("2001:0db8:0000:0000:0000:0000:1428:57ab")); + assertTrue("IPV6 2001:0db8:0000:0000:0000::1428:57ab should be valid", validator.isValidInet6Address("2001:0db8:0000:0000:0000::1428:57ab")); + assertTrue("IPV6 2001:0db8:0:0:0:0:1428:57ab should be valid", validator.isValidInet6Address("2001:0db8:0:0:0:0:1428:57ab")); + assertTrue("IPV6 2001:0db8:0:0::1428:57ab should be valid", validator.isValidInet6Address("2001:0db8:0:0::1428:57ab")); + assertTrue("IPV6 2001:0db8::1428:57ab should be valid", validator.isValidInet6Address("2001:0db8::1428:57ab")); + assertTrue("IPV6 2001:db8::1428:57ab should be valid", validator.isValidInet6Address("2001:db8::1428:57ab")); + assertTrue("IPV6 ::ffff:0c22:384e should be valid", validator.isValidInet6Address("::ffff:0c22:384e")); + assertTrue("IPV6 2001:0db8:1234:0000:0000:0000:0000:0000 should be valid", validator.isValidInet6Address("2001:0db8:1234:0000:0000:0000:0000:0000")); + assertTrue("IPV6 2001:0db8:1234:ffff:ffff:ffff:ffff:ffff should be valid", validator.isValidInet6Address("2001:0db8:1234:ffff:ffff:ffff:ffff:ffff")); + assertTrue("IPV6 2001:db8:a::123 should be valid", validator.isValidInet6Address("2001:db8:a::123")); + assertFalse("IPV6 123 should be invalid", validator.isValidInet6Address("123")); + assertFalse("IPV6 ldkfj should be invalid", validator.isValidInet6Address("ldkfj")); + assertFalse("IPV6 2001::FFD3::57ab should be invalid", validator.isValidInet6Address("2001::FFD3::57ab")); + assertFalse("IPV6 2001:db8:85a3::8a2e:37023:7334 should be invalid", validator.isValidInet6Address("2001:db8:85a3::8a2e:37023:7334")); + assertFalse("IPV6 2001:db8:85a3::8a2e:370k:7334 should be invalid", validator.isValidInet6Address("2001:db8:85a3::8a2e:370k:7334")); + assertFalse("IPV6 1:2:3:4:5:6:7:8:9 should be invalid", validator.isValidInet6Address("1:2:3:4:5:6:7:8:9")); + assertFalse("IPV6 1::2::3 should be invalid", validator.isValidInet6Address("1::2::3")); + assertFalse("IPV6 1:::3:4:5 should be invalid", validator.isValidInet6Address("1:::3:4:5")); + assertFalse("IPV6 1:2:3::4:5:6:7:8:9 should be invalid", validator.isValidInet6Address("1:2:3::4:5:6:7:8:9")); + assertTrue("IPV6 1111:2222:3333:4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:8888")); + assertTrue("IPV6 1111:2222:3333:4444:5555:6666:7777:: should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777::")); + assertTrue("IPV6 1111:2222:3333:4444:5555:6666:: should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666::")); + assertTrue("IPV6 1111:2222:3333:4444:5555:: should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555::")); + assertTrue("IPV6 1111:2222:3333:4444:: should be valid", validator.isValidInet6Address("1111:2222:3333:4444::")); + assertTrue("IPV6 1111:2222:3333:: should be valid", validator.isValidInet6Address("1111:2222:3333::")); + assertTrue("IPV6 1111:2222:: should be valid", validator.isValidInet6Address("1111:2222::")); + assertTrue("IPV6 1111:: should be valid", validator.isValidInet6Address("1111::")); + assertTrue("IPV6 1111:2222:3333:4444:5555:6666::8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666::8888")); + assertTrue("IPV6 1111:2222:3333:4444:5555::8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555::8888")); + assertTrue("IPV6 1111:2222:3333:4444::8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444::8888")); + assertTrue("IPV6 1111:2222:3333::8888 should be valid", validator.isValidInet6Address("1111:2222:3333::8888")); + assertTrue("IPV6 1111:2222::8888 should be valid", validator.isValidInet6Address("1111:2222::8888")); + assertTrue("IPV6 1111::8888 should be valid", validator.isValidInet6Address("1111::8888")); + assertTrue("IPV6 ::8888 should be valid", validator.isValidInet6Address("::8888")); + assertTrue("IPV6 1111:2222:3333:4444:5555::7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555::7777:8888")); + assertTrue("IPV6 1111:2222:3333:4444::7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444::7777:8888")); + assertTrue("IPV6 1111:2222:3333::7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333::7777:8888")); + assertTrue("IPV6 1111:2222::7777:8888 should be valid", validator.isValidInet6Address("1111:2222::7777:8888")); + assertTrue("IPV6 1111::7777:8888 should be valid", validator.isValidInet6Address("1111::7777:8888")); + assertTrue("IPV6 ::7777:8888 should be valid", validator.isValidInet6Address("::7777:8888")); + assertTrue("IPV6 1111:2222:3333:4444::6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444::6666:7777:8888")); + assertTrue("IPV6 1111:2222:3333::6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333::6666:7777:8888")); + assertTrue("IPV6 1111:2222::6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222::6666:7777:8888")); + assertTrue("IPV6 1111::6666:7777:8888 should be valid", validator.isValidInet6Address("1111::6666:7777:8888")); + assertTrue("IPV6 ::6666:7777:8888 should be valid", validator.isValidInet6Address("::6666:7777:8888")); + assertTrue("IPV6 1111:2222:3333::5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333::5555:6666:7777:8888")); + assertTrue("IPV6 1111:2222::5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222::5555:6666:7777:8888")); + assertTrue("IPV6 1111::5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111::5555:6666:7777:8888")); + assertTrue("IPV6 ::5555:6666:7777:8888 should be valid", validator.isValidInet6Address("::5555:6666:7777:8888")); + assertTrue("IPV6 1111:2222::4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222::4444:5555:6666:7777:8888")); + assertTrue("IPV6 1111::4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111::4444:5555:6666:7777:8888")); + assertTrue("IPV6 ::4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("::4444:5555:6666:7777:8888")); + assertTrue("IPV6 1111::3333:4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111::3333:4444:5555:6666:7777:8888")); + assertTrue("IPV6 ::3333:4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("::3333:4444:5555:6666:7777:8888")); + assertTrue("IPV6 ::2222:3333:4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("::2222:3333:4444:5555:6666:7777:8888")); + assertTrue("IPV6 1111:2222:3333:4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:123.123.123.123")); + assertTrue("IPV6 1111:2222:3333:4444:5555::123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555::123.123.123.123")); + assertTrue("IPV6 1111:2222:3333:4444::123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333:4444::123.123.123.123")); + assertTrue("IPV6 1111:2222:3333::123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333::123.123.123.123")); + assertTrue("IPV6 1111:2222::123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222::123.123.123.123")); + assertTrue("IPV6 1111::123.123.123.123 should be valid", validator.isValidInet6Address("1111::123.123.123.123")); + assertTrue("IPV6 ::123.123.123.123 should be valid", validator.isValidInet6Address("::123.123.123.123")); + assertTrue("IPV6 1111:2222:3333:4444::6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333:4444::6666:123.123.123.123")); + assertTrue("IPV6 1111:2222:3333::6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333::6666:123.123.123.123")); + assertTrue("IPV6 1111:2222::6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222::6666:123.123.123.123")); + assertTrue("IPV6 1111::6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111::6666:123.123.123.123")); + assertTrue("IPV6 ::6666:123.123.123.123 should be valid", validator.isValidInet6Address("::6666:123.123.123.123")); + assertTrue("IPV6 1111:2222:3333::5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333::5555:6666:123.123.123.123")); + assertTrue("IPV6 1111:2222::5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222::5555:6666:123.123.123.123")); + assertTrue("IPV6 1111::5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111::5555:6666:123.123.123.123")); + assertTrue("IPV6 ::5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("::5555:6666:123.123.123.123")); + assertTrue("IPV6 1111:2222::4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222::4444:5555:6666:123.123.123.123")); + assertTrue("IPV6 1111::4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111::4444:5555:6666:123.123.123.123")); + assertTrue("IPV6 ::4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("::4444:5555:6666:123.123.123.123")); + assertTrue("IPV6 1111::3333:4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111::3333:4444:5555:6666:123.123.123.123")); + assertTrue("IPV6 ::2222:3333:4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("::2222:3333:4444:5555:6666:123.123.123.123")); + // Trying combinations of "0" and "::" + // These are all syntactically correct, but are bad form + // because "0" adjacent to "::" should be combined into "::" + assertTrue("IPV6 ::0:0:0:0:0:0:0 should be valid", validator.isValidInet6Address("::0:0:0:0:0:0:0")); + assertTrue("IPV6 ::0:0:0:0:0:0 should be valid", validator.isValidInet6Address("::0:0:0:0:0:0")); + assertTrue("IPV6 ::0:0:0:0:0 should be valid", validator.isValidInet6Address("::0:0:0:0:0")); + assertTrue("IPV6 ::0:0:0:0 should be valid", validator.isValidInet6Address("::0:0:0:0")); + assertTrue("IPV6 ::0:0:0 should be valid", validator.isValidInet6Address("::0:0:0")); + assertTrue("IPV6 ::0:0 should be valid", validator.isValidInet6Address("::0:0")); + assertTrue("IPV6 ::0 should be valid", validator.isValidInet6Address("::0")); + assertTrue("IPV6 0:0:0:0:0:0:0:: should be valid", validator.isValidInet6Address("0:0:0:0:0:0:0::")); + assertTrue("IPV6 0:0:0:0:0:0:: should be valid", validator.isValidInet6Address("0:0:0:0:0:0::")); + assertTrue("IPV6 0:0:0:0:0:: should be valid", validator.isValidInet6Address("0:0:0:0:0::")); + assertTrue("IPV6 0:0:0:0:: should be valid", validator.isValidInet6Address("0:0:0:0::")); + assertTrue("IPV6 0:0:0:: should be valid", validator.isValidInet6Address("0:0:0::")); + assertTrue("IPV6 0:0:: should be valid", validator.isValidInet6Address("0:0::")); + assertTrue("IPV6 0:: should be valid", validator.isValidInet6Address("0::")); + // Invalid data + assertFalse("IPV6 XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX should be invalid", validator.isValidInet6Address("XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX")); + // Too many components + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777:8888:9999 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:8888:9999")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777:8888:: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:8888::")); + assertFalse("IPV6 ::2222:3333:4444:5555:6666:7777:8888:9999 should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555:6666:7777:8888:9999")); + // Too few components + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666")); + assertFalse("IPV6 1111:2222:3333:4444:5555 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555")); + assertFalse("IPV6 1111:2222:3333:4444 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444")); + assertFalse("IPV6 1111:2222:3333 should be invalid", validator.isValidInet6Address("1111:2222:3333")); + assertFalse("IPV6 1111:2222 should be invalid", validator.isValidInet6Address("1111:2222")); + assertFalse("IPV6 1111 should be invalid", validator.isValidInet6Address("1111")); + // Missing : + assertFalse("IPV6 11112222:3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("11112222:3333:4444:5555:6666:7777:8888")); + assertFalse("IPV6 1111:22223333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:22223333:4444:5555:6666:7777:8888")); + assertFalse("IPV6 1111:2222:33334444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:33334444:5555:6666:7777:8888")); + assertFalse("IPV6 1111:2222:3333:44445555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:44445555:6666:7777:8888")); + assertFalse("IPV6 1111:2222:3333:4444:55556666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:55556666:7777:8888")); + assertFalse("IPV6 1111:2222:3333:4444:5555:66667777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:66667777:8888")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:77778888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:77778888")); + // Missing : intended for :: + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:8888:")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:")); + assertFalse("IPV6 1111:2222:3333:4444:5555: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:")); + assertFalse("IPV6 1111:2222:3333:4444: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:")); + assertFalse("IPV6 1111:2222:3333: should be invalid", validator.isValidInet6Address("1111:2222:3333:")); + assertFalse("IPV6 1111:2222: should be invalid", validator.isValidInet6Address("1111:2222:")); + assertFalse("IPV6 :8888 should be invalid", validator.isValidInet6Address(":8888")); + assertFalse("IPV6 :7777:8888 should be invalid", validator.isValidInet6Address(":7777:8888")); + assertFalse("IPV6 :6666:7777:8888 should be invalid", validator.isValidInet6Address(":6666:7777:8888")); + assertFalse("IPV6 :5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":5555:6666:7777:8888")); + assertFalse("IPV6 :4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":4444:5555:6666:7777:8888")); + assertFalse("IPV6 :3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":3333:4444:5555:6666:7777:8888")); + assertFalse("IPV6 :2222:3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":2222:3333:4444:5555:6666:7777:8888")); + assertFalse("IPV6 :1111:2222:3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666:7777:8888")); + // ::: + assertFalse("IPV6 :::2222:3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":::2222:3333:4444:5555:6666:7777:8888")); + assertFalse("IPV6 1111:::3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:::3333:4444:5555:6666:7777:8888")); + assertFalse("IPV6 1111:2222:::4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:::4444:5555:6666:7777:8888")); + assertFalse("IPV6 1111:2222:3333:::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:::5555:6666:7777:8888")); + assertFalse("IPV6 1111:2222:3333:4444:::6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:::6666:7777:8888")); + assertFalse("IPV6 1111:2222:3333:4444:5555:::7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:::7777:8888")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:::8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:::8888")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777::: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:::")); + // Double :: + assertFalse("IPV6 ::2222::4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("::2222::4444:5555:6666:7777:8888")); + assertFalse("IPV6 ::2222:3333::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("::2222:3333::5555:6666:7777:8888")); + assertFalse("IPV6 ::2222:3333:4444::6666:7777:8888 should be invalid", validator.isValidInet6Address("::2222:3333:4444::6666:7777:8888")); + assertFalse("IPV6 ::2222:3333:4444:5555::7777:8888 should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555::7777:8888")); + assertFalse("IPV6 ::2222:3333:4444:5555:7777::8888 should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555:7777::8888")); + assertFalse("IPV6 ::2222:3333:4444:5555:7777:8888:: should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555:7777:8888::")); + assertFalse("IPV6 1111::3333::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111::3333::5555:6666:7777:8888")); + assertFalse("IPV6 1111::3333:4444::6666:7777:8888 should be invalid", validator.isValidInet6Address("1111::3333:4444::6666:7777:8888")); + assertFalse("IPV6 1111::3333:4444:5555::7777:8888 should be invalid", validator.isValidInet6Address("1111::3333:4444:5555::7777:8888")); + assertFalse("IPV6 1111::3333:4444:5555:6666::8888 should be invalid", validator.isValidInet6Address("1111::3333:4444:5555:6666::8888")); + assertFalse("IPV6 1111::3333:4444:5555:6666:7777:: should be invalid", validator.isValidInet6Address("1111::3333:4444:5555:6666:7777::")); + assertFalse("IPV6 1111:2222::4444::6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222::4444::6666:7777:8888")); + assertFalse("IPV6 1111:2222::4444:5555::7777:8888 should be invalid", validator.isValidInet6Address("1111:2222::4444:5555::7777:8888")); + assertFalse("IPV6 1111:2222::4444:5555:6666::8888 should be invalid", validator.isValidInet6Address("1111:2222::4444:5555:6666::8888")); + assertFalse("IPV6 1111:2222::4444:5555:6666:7777:: should be invalid", validator.isValidInet6Address("1111:2222::4444:5555:6666:7777::")); + assertFalse("IPV6 1111:2222:3333::5555::7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333::5555::7777:8888")); + assertFalse("IPV6 1111:2222:3333::5555:6666::8888 should be invalid", validator.isValidInet6Address("1111:2222:3333::5555:6666::8888")); + assertFalse("IPV6 1111:2222:3333::5555:6666:7777:: should be invalid", validator.isValidInet6Address("1111:2222:3333::5555:6666:7777::")); + assertFalse("IPV6 1111:2222:3333:4444::6666::8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::6666::8888")); + assertFalse("IPV6 1111:2222:3333:4444::6666:7777:: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::6666:7777::")); + assertFalse("IPV6 1111:2222:3333:4444:5555::7777:: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555::7777::")); + // Too many components" + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666::1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666::1.2.3.4")); + assertFalse("IPV6 ::2222:3333:4444:5555:6666:7777:1.2.3.4 should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555:6666:7777:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:1.2.3.4.5 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:1.2.3.4.5")); + // Too few components + assertFalse("IPV6 1111:2222:3333:4444:5555:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:4444:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:1.2.3.4")); + assertFalse("IPV6 1111:2222:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:1.2.3.4")); + assertFalse("IPV6 1111:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:1.2.3.4")); + assertFalse("IPV6 1.2.3.4 should be invalid", validator.isValidInet6Address("1.2.3.4")); + // Missing : + assertFalse("IPV6 11112222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("11112222:3333:4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 1111:22223333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:22223333:4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 1111:2222:33334444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:33334444:5555:6666:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:44445555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:44445555:6666:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:4444:55556666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:55556666:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:4444:5555:66661.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:66661.2.3.4")); + // Missing . + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:255255.255.255 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:255255.255.255")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:255.255255.255 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:255.255255.255")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:255.255.255255 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:255.255.255255")); + // Missing : intended for :: + assertFalse("IPV6 :1.2.3.4 should be invalid", validator.isValidInet6Address(":1.2.3.4")); + assertFalse("IPV6 :6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":6666:1.2.3.4")); + assertFalse("IPV6 :5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":5555:6666:1.2.3.4")); + assertFalse("IPV6 :4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 :3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":3333:4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 :2222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":2222:3333:4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 :1111:2222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666:1.2.3.4")); + // ::: + assertFalse("IPV6 :::2222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":::2222:3333:4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 1111:::3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:::3333:4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 1111:2222:::4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:::4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:::5555:6666:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:4444:::6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:::6666:1.2.3.4")); + assertFalse("IPV6 1111:2222:3333:4444:5555:::1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:::1.2.3.4")); + // Double :: + assertFalse("IPV6 ::2222::4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("::2222::4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 ::2222:3333::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("::2222:3333::5555:6666:1.2.3.4")); + assertFalse("IPV6 ::2222:3333:4444::6666:1.2.3.4 should be invalid", validator.isValidInet6Address("::2222:3333:4444::6666:1.2.3.4")); + assertFalse("IPV6 ::2222:3333:4444:5555::1.2.3.4 should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555::1.2.3.4")); + assertFalse("IPV6 1111::3333::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111::3333::5555:6666:1.2.3.4")); + assertFalse("IPV6 1111::3333:4444::6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111::3333:4444::6666:1.2.3.4")); + assertFalse("IPV6 1111::3333:4444:5555::1.2.3.4 should be invalid", validator.isValidInet6Address("1111::3333:4444:5555::1.2.3.4")); + assertFalse("IPV6 1111:2222::4444::6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222::4444::6666:1.2.3.4")); + assertFalse("IPV6 1111:2222::4444:5555::1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222::4444:5555::1.2.3.4")); + assertFalse("IPV6 1111:2222:3333::5555::1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333::5555::1.2.3.4")); + // Missing parts + assertFalse("IPV6 ::. should be invalid", validator.isValidInet6Address("::.")); + assertFalse("IPV6 ::.. should be invalid", validator.isValidInet6Address("::..")); + assertFalse("IPV6 ::... should be invalid", validator.isValidInet6Address("::...")); + assertFalse("IPV6 ::1... should be invalid", validator.isValidInet6Address("::1...")); + assertFalse("IPV6 ::1.2.. should be invalid", validator.isValidInet6Address("::1.2..")); + assertFalse("IPV6 ::1.2.3. should be invalid", validator.isValidInet6Address("::1.2.3.")); + assertFalse("IPV6 ::.2.. should be invalid", validator.isValidInet6Address("::.2..")); + assertFalse("IPV6 ::.2.3. should be invalid", validator.isValidInet6Address("::.2.3.")); + assertFalse("IPV6 ::.2.3.4 should be invalid", validator.isValidInet6Address("::.2.3.4")); + assertFalse("IPV6 ::..3. should be invalid", validator.isValidInet6Address("::..3.")); + assertFalse("IPV6 ::..3.4 should be invalid", validator.isValidInet6Address("::..3.4")); + assertFalse("IPV6 ::...4 should be invalid", validator.isValidInet6Address("::...4")); + // Extra : in front + assertFalse("IPV6 :1111:2222:3333:4444:5555:6666:7777:: should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666:7777::")); + assertFalse("IPV6 :1111:2222:3333:4444:5555:6666:: should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666::")); + assertFalse("IPV6 :1111:2222:3333:4444:5555:: should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555::")); + assertFalse("IPV6 :1111:2222:3333:4444:: should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::")); + assertFalse("IPV6 :1111:2222:3333:: should be invalid", validator.isValidInet6Address(":1111:2222:3333::")); + assertFalse("IPV6 :1111:2222:: should be invalid", validator.isValidInet6Address(":1111:2222::")); + assertFalse("IPV6 :1111:: should be invalid", validator.isValidInet6Address(":1111::")); + assertFalse("IPV6 :1111:2222:3333:4444:5555:6666::8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666::8888")); + assertFalse("IPV6 :1111:2222:3333:4444:5555::8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555::8888")); + assertFalse("IPV6 :1111:2222:3333:4444::8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::8888")); + assertFalse("IPV6 :1111:2222:3333::8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333::8888")); + assertFalse("IPV6 :1111:2222::8888 should be invalid", validator.isValidInet6Address(":1111:2222::8888")); + assertFalse("IPV6 :1111::8888 should be invalid", validator.isValidInet6Address(":1111::8888")); + assertFalse("IPV6 :::8888 should be invalid", validator.isValidInet6Address(":::8888")); + assertFalse("IPV6 :1111:2222:3333:4444:5555::7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555::7777:8888")); + assertFalse("IPV6 :1111:2222:3333:4444::7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::7777:8888")); + assertFalse("IPV6 :1111:2222:3333::7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333::7777:8888")); + assertFalse("IPV6 :1111:2222::7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222::7777:8888")); + assertFalse("IPV6 :1111::7777:8888 should be invalid", validator.isValidInet6Address(":1111::7777:8888")); + assertFalse("IPV6 :::7777:8888 should be invalid", validator.isValidInet6Address(":::7777:8888")); + assertFalse("IPV6 :1111:2222:3333:4444::6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::6666:7777:8888")); + assertFalse("IPV6 :1111:2222:3333::6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333::6666:7777:8888")); + assertFalse("IPV6 :1111:2222::6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222::6666:7777:8888")); + assertFalse("IPV6 :1111::6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111::6666:7777:8888")); + assertFalse("IPV6 :::6666:7777:8888 should be invalid", validator.isValidInet6Address(":::6666:7777:8888")); + assertFalse("IPV6 :1111:2222:3333::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333::5555:6666:7777:8888")); + assertFalse("IPV6 :1111:2222::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222::5555:6666:7777:8888")); + assertFalse("IPV6 :1111::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111::5555:6666:7777:8888")); + assertFalse("IPV6 :::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":::5555:6666:7777:8888")); + assertFalse("IPV6 :1111:2222::4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222::4444:5555:6666:7777:8888")); + assertFalse("IPV6 :1111::4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111::4444:5555:6666:7777:8888")); + assertFalse("IPV6 :::4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":::4444:5555:6666:7777:8888")); + assertFalse("IPV6 :1111::3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111::3333:4444:5555:6666:7777:8888")); + assertFalse("IPV6 :::3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":::3333:4444:5555:6666:7777:8888")); + assertFalse("IPV6 :::2222:3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":::2222:3333:4444:5555:6666:7777:8888")); + assertFalse("IPV6 :1111:2222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 :1111:2222:3333:4444:5555::1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555::1.2.3.4")); + assertFalse("IPV6 :1111:2222:3333:4444::1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::1.2.3.4")); + assertFalse("IPV6 :1111:2222:3333::1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333::1.2.3.4")); + assertFalse("IPV6 :1111:2222::1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222::1.2.3.4")); + assertFalse("IPV6 :1111::1.2.3.4 should be invalid", validator.isValidInet6Address(":1111::1.2.3.4")); + assertFalse("IPV6 :::1.2.3.4 should be invalid", validator.isValidInet6Address(":::1.2.3.4")); + assertFalse("IPV6 :1111:2222:3333:4444::6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::6666:1.2.3.4")); + assertFalse("IPV6 :1111:2222:3333::6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333::6666:1.2.3.4")); + assertFalse("IPV6 :1111:2222::6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222::6666:1.2.3.4")); + assertFalse("IPV6 :1111::6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111::6666:1.2.3.4")); + assertFalse("IPV6 :::6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":::6666:1.2.3.4")); + assertFalse("IPV6 :1111:2222:3333::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333::5555:6666:1.2.3.4")); + assertFalse("IPV6 :1111:2222::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222::5555:6666:1.2.3.4")); + assertFalse("IPV6 :1111::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111::5555:6666:1.2.3.4")); + assertFalse("IPV6 :::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":::5555:6666:1.2.3.4")); + assertFalse("IPV6 :1111:2222::4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222::4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 :1111::4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111::4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 :::4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":::4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 :1111::3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111::3333:4444:5555:6666:1.2.3.4")); + assertFalse("IPV6 :::2222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":::2222:3333:4444:5555:6666:1.2.3.4")); + // Extra : at end + assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777::: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:::")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666::: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:::")); + assertFalse("IPV6 1111:2222:3333:4444:5555::: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:::")); + assertFalse("IPV6 1111:2222:3333:4444::: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:::")); + assertFalse("IPV6 1111:2222:3333::: should be invalid", validator.isValidInet6Address("1111:2222:3333:::")); + assertFalse("IPV6 1111:2222::: should be invalid", validator.isValidInet6Address("1111:2222:::")); + assertFalse("IPV6 1111::: should be invalid", validator.isValidInet6Address("1111:::")); + assertFalse("IPV6 1111:2222:3333:4444:5555:6666::8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666::8888:")); + assertFalse("IPV6 1111:2222:3333:4444:5555::8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555::8888:")); + assertFalse("IPV6 1111:2222:3333:4444::8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::8888:")); + assertFalse("IPV6 1111:2222:3333::8888: should be invalid", validator.isValidInet6Address("1111:2222:3333::8888:")); + assertFalse("IPV6 1111:2222::8888: should be invalid", validator.isValidInet6Address("1111:2222::8888:")); + assertFalse("IPV6 1111::8888: should be invalid", validator.isValidInet6Address("1111::8888:")); + assertFalse("IPV6 ::8888: should be invalid", validator.isValidInet6Address("::8888:")); + assertFalse("IPV6 1111:2222:3333:4444:5555::7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555::7777:8888:")); + assertFalse("IPV6 1111:2222:3333:4444::7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::7777:8888:")); + assertFalse("IPV6 1111:2222:3333::7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333::7777:8888:")); + assertFalse("IPV6 1111:2222::7777:8888: should be invalid", validator.isValidInet6Address("1111:2222::7777:8888:")); + assertFalse("IPV6 1111::7777:8888: should be invalid", validator.isValidInet6Address("1111::7777:8888:")); + assertFalse("IPV6 ::7777:8888: should be invalid", validator.isValidInet6Address("::7777:8888:")); + assertFalse("IPV6 1111:2222:3333:4444::6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::6666:7777:8888:")); + assertFalse("IPV6 1111:2222:3333::6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333::6666:7777:8888:")); + assertFalse("IPV6 1111:2222::6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222::6666:7777:8888:")); + assertFalse("IPV6 1111::6666:7777:8888: should be invalid", validator.isValidInet6Address("1111::6666:7777:8888:")); + assertFalse("IPV6 ::6666:7777:8888: should be invalid", validator.isValidInet6Address("::6666:7777:8888:")); + assertFalse("IPV6 1111:2222:3333::5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333::5555:6666:7777:8888:")); + assertFalse("IPV6 1111:2222::5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222::5555:6666:7777:8888:")); + assertFalse("IPV6 1111::5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111::5555:6666:7777:8888:")); + assertFalse("IPV6 ::5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("::5555:6666:7777:8888:")); + assertFalse("IPV6 1111:2222::4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222::4444:5555:6666:7777:8888:")); + assertFalse("IPV6 1111::4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111::4444:5555:6666:7777:8888:")); + assertFalse("IPV6 ::4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("::4444:5555:6666:7777:8888:")); + assertFalse("IPV6 1111::3333:4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111::3333:4444:5555:6666:7777:8888:")); + assertFalse("IPV6 ::3333:4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("::3333:4444:5555:6666:7777:8888:")); + assertFalse("IPV6 ::2222:3333:4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555:6666:7777:8888:")); + assertTrue("IPV6 0:a:b:c:d:e:f:: should be valid", validator.isValidInet6Address("0:a:b:c:d:e:f::")); + assertTrue("IPV6 ::0:a:b:c:d:e:f should be valid", validator.isValidInet6Address("::0:a:b:c:d:e:f")); // syntactically correct, but bad form (::0:... could be combined) + assertTrue("IPV6 a:b:c:d:e:f:0:: should be valid", validator.isValidInet6Address("a:b:c:d:e:f:0::")); + assertFalse("IPV6 ':10.0.0.1 should be invalid", validator.isValidInet6Address("':10.0.0.1")); + } +} + + diff --git a/core/src/test/java/jenkins/org/apache/commons/validator/routines/RegexValidatorTest.java b/core/src/test/java/jenkins/org/apache/commons/validator/routines/RegexValidatorTest.java new file mode 100644 index 000000000000..bb05321fb323 --- /dev/null +++ b/core/src/test/java/jenkins/org/apache/commons/validator/routines/RegexValidatorTest.java @@ -0,0 +1,280 @@ +/* + * 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 jenkins.org.apache.commons.validator.routines; + +import java.util.Arrays; +import java.util.regex.PatternSyntaxException; +import junit.framework.TestCase; + +/** + * Test Case for RegexValidatorTest. + * + * @version $Revision$ + * @since Validator 1.4 + */ +public class RegexValidatorTest extends TestCase { + + private static final String REGEX = "^([abc]*)(?:\\-)([DEF]*)(?:\\-)([123]*)$"; + + private static final String COMPONENT_1 = "([abc]{3})"; + private static final String COMPONENT_2 = "([DEF]{3})"; + private static final String COMPONENT_3 = "([123]{3})"; + private static final String SEPARATOR_1 = "(?:\\-)"; + private static final String SEPARATOR_2 = "(?:\\s)"; + private static final String REGEX_1 = "^" + COMPONENT_1 + SEPARATOR_1 + COMPONENT_2 + SEPARATOR_1 + COMPONENT_3 + "$"; + private static final String REGEX_2 = "^" + COMPONENT_1 + SEPARATOR_2 + COMPONENT_2 + SEPARATOR_2 + COMPONENT_3 + "$"; + private static final String REGEX_3 = "^" + COMPONENT_1 + COMPONENT_2 + COMPONENT_3 + "$"; + private static final String[] MULTIPLE_REGEX = new String[] {REGEX_1, REGEX_2, REGEX_3}; + + /** + * Constrct a new test case. + * @param name The name of the test + */ + public RegexValidatorTest(String name) { + super(name); + } + + /** + * Test instance methods with single regular expression. + */ + public void testSingle() { + RegexValidator sensitive = new RegexValidator(REGEX); + RegexValidator insensitive = new RegexValidator(REGEX, false); + + // isValid() + assertTrue("Sensitive isValid() valid", sensitive.isValid("ac-DE-1")); + assertFalse("Sensitive isValid() invalid", sensitive.isValid("AB-de-1")); + assertTrue("Insensitive isValid() valid", insensitive.isValid("AB-de-1")); + assertFalse("Insensitive isValid() invalid", insensitive.isValid("ABd-de-1")); + + // validate() + assertEquals("Sensitive validate() valid", "acDE1", sensitive.validate("ac-DE-1")); + assertNull("Sensitive validate() invalid", sensitive.validate("AB-de-1")); + assertEquals("Insensitive validate() valid", "ABde1", insensitive.validate("AB-de-1")); + assertNull("Insensitive validate() invalid", insensitive.validate("ABd-de-1")); + + // match() + checkArray("Sensitive match() valid", new String[] {"ac", "DE", "1"}, sensitive.match("ac-DE-1")); + checkArray("Sensitive match() invalid", null, sensitive.match("AB-de-1")); + checkArray("Insensitive match() valid", new String[] {"AB", "de", "1"}, insensitive.match("AB-de-1")); + checkArray("Insensitive match() invalid", null, insensitive.match("ABd-de-1")); + assertEquals("validate one", "ABC", (new RegexValidator("^([A-Z]*)$")).validate("ABC")); + checkArray("match one", new String[] {"ABC"}, (new RegexValidator("^([A-Z]*)$")).match("ABC")); + } + + /** + * Test with multiple regular expressions (case sensitive). + */ + public void testMultipleSensitive() { + + // ------------ Set up Sensitive Validators + RegexValidator multiple = new RegexValidator(MULTIPLE_REGEX); + RegexValidator single1 = new RegexValidator(REGEX_1); + RegexValidator single2 = new RegexValidator(REGEX_2); + RegexValidator single3 = new RegexValidator(REGEX_3); + + // ------------ Set up test values + String value = "aac FDE 321"; + String expect = "aacFDE321"; + String[] array = new String[] {"aac", "FDE", "321"}; + + // isValid() + assertTrue("Sensitive isValid() Multiple", multiple.isValid(value)); + assertFalse("Sensitive isValid() 1st", single1.isValid(value)); + assertTrue("Sensitive isValid() 2nd", single2.isValid(value)); + assertFalse("Sensitive isValid() 3rd", single3.isValid(value)); + + // validate() + assertEquals("Sensitive validate() Multiple", expect, multiple.validate(value)); + assertNull("Sensitive validate() 1st", single1.validate(value)); + assertEquals("Sensitive validate() 2nd", expect, single2.validate(value)); + assertNull("Sensitive validate() 3rd", single3.validate(value)); + + // match() + checkArray("Sensitive match() Multiple", array, multiple.match(value)); + checkArray("Sensitive match() 1st", null, single1.match(value)); + checkArray("Sensitive match() 2nd", array, single2.match(value)); + checkArray("Sensitive match() 3rd", null, single3.match(value)); + + // All invalid + value = "AAC*FDE*321"; + assertFalse("isValid() Invalid", multiple.isValid(value)); + assertNull("validate() Invalid", multiple.validate(value)); + assertNull("match() Multiple", multiple.match(value)); + } + + /** + * Test with multiple regular expressions (case in-sensitive). + */ + public void testMultipleInsensitive() { + + // ------------ Set up In-sensitive Validators + RegexValidator multiple = new RegexValidator(MULTIPLE_REGEX, false); + RegexValidator single1 = new RegexValidator(REGEX_1, false); + RegexValidator single2 = new RegexValidator(REGEX_2, false); + RegexValidator single3 = new RegexValidator(REGEX_3, false); + + // ------------ Set up test values + String value = "AAC FDE 321"; + String expect = "AACFDE321"; + String[] array = new String[] {"AAC", "FDE", "321"}; + + // isValid() + assertTrue("isValid() Multiple", multiple.isValid(value)); + assertFalse("isValid() 1st", single1.isValid(value)); + assertTrue("isValid() 2nd", single2.isValid(value)); + assertFalse("isValid() 3rd", single3.isValid(value)); + + // validate() + assertEquals("validate() Multiple", expect, multiple.validate(value)); + assertNull("validate() 1st", single1.validate(value)); + assertEquals("validate() 2nd", expect, single2.validate(value)); + assertNull("validate() 3rd", single3.validate(value)); + + // match() + checkArray("match() Multiple", array, multiple.match(value)); + checkArray("match() 1st", null, single1.match(value)); + checkArray("match() 2nd", array, single2.match(value)); + checkArray("match() 3rd", null, single3.match(value)); + + // All invalid + value = "AAC*FDE*321"; + assertFalse("isValid() Invalid", multiple.isValid(value)); + assertNull("validate() Invalid", multiple.validate(value)); + assertNull("match() Multiple", multiple.match(value)); + } + + /** + * Test Null value + */ + public void testNullValue() { + + RegexValidator validator = new RegexValidator(REGEX); + assertFalse("Instance isValid()", validator.isValid(null)); + assertNull("Instance validate()", validator.validate(null)); + assertNull("Instance match()", validator.match(null)); + } + + /** + * Test exceptions + */ + public void testMissingRegex() { + + // Single Regular Expression - null + try { + new RegexValidator((String)null); + fail("Single Null - expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + assertEquals("Single Null", "Regular expression[0] is missing", e.getMessage()); + } + + // Single Regular Expression - Zero Length + try { + new RegexValidator(""); + fail("Single Zero Length - expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + assertEquals("Single Zero Length", "Regular expression[0] is missing", e.getMessage()); + } + + // Multiple Regular Expression - Null array + try { + new RegexValidator((String[])null); + fail("Null Array - expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + assertEquals("Null Array", "Regular expressions are missing", e.getMessage()); + } + + // Multiple Regular Expression - Zero Length array + try { + new RegexValidator(new String[0]); + fail("Zero Length Array - expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + assertEquals("Zero Length Array", "Regular expressions are missing", e.getMessage()); + } + + // Multiple Regular Expression - Array has Null + String[] expressions = new String[] {"ABC", null}; + try { + new RegexValidator(expressions); + fail("Array has Null - expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + assertEquals("Array has Null", "Regular expression[1] is missing", e.getMessage()); + } + + // Multiple Regular Expression - Array has Zero Length + expressions = new String[] {"", "ABC"}; + try { + new RegexValidator(expressions); + fail("Array has Zero Length - expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + assertEquals("Array has Zero Length", "Regular expression[0] is missing", e.getMessage()); + } + } + + /** + * Test exceptions + */ + public void testExceptions() { + String invalidRegex = "^([abCD12]*$"; + try { + new RegexValidator(invalidRegex); + } catch (PatternSyntaxException e) { + // expected + } + } + + /** + * Test toString() method + */ + public void testToString() { + RegexValidator single = new RegexValidator(REGEX); + assertEquals("Single", "RegexValidator{" + REGEX + "}", single.toString()); + + RegexValidator multiple = new RegexValidator(new String[] {REGEX, REGEX}); + assertEquals("Multiple", "RegexValidator{" + REGEX + "," + REGEX + "}", multiple.toString()); + } + + /** + * Compare two arrays + * @param label Label for the test + * @param expect Expected array + * @param result Actual array + */ + private void checkArray(String label, String[] expect, String[] result) { + + // Handle nulls + if (expect == null || result == null) { + if (expect == null && result == null) { + return; // valid, both null + } else { + fail(label + " Null expect=" + Arrays.toString(expect) + " result=" + Arrays.toString(result)); + } + return; // not strictly necessary, but prevents possible NPE below + } + + // Check Length + if (expect.length != result.length) { + fail(label + " Length expect=" + expect.length + " result=" + result.length); + } + + // Check Values + for (int i = 0; i < expect.length; i++) { + assertEquals(label +" value[" + i + "]", expect[i], result[i]); + } + } + +} diff --git a/core/src/test/java/jenkins/org/apache/commons/validator/routines/UrlValidatorTest.java b/core/src/test/java/jenkins/org/apache/commons/validator/routines/UrlValidatorTest.java new file mode 100644 index 000000000000..dcf8c16208ba --- /dev/null +++ b/core/src/test/java/jenkins/org/apache/commons/validator/routines/UrlValidatorTest.java @@ -0,0 +1,719 @@ +/* + * 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 jenkins.org.apache.commons.validator.routines; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import jenkins.org.apache.commons.validator.ResultPair; +import org.junit.Before; +import org.junit.Test; + +/** + * Performs Validation Test for url validations. + * + * @version $Revision$ + */ +public class UrlValidatorTest { + + private final boolean printStatus = false; + private final boolean printIndex = false;//print index that indicates current scheme,host,port,path, query test were using. + + @Before + public void setUp() { + for (int index = 0; index < testPartsIndex.length - 1; index++) { + testPartsIndex[index] = 0; + } + } + + @Test + public void testIsValid() { + testIsValid(testUrlParts, UrlValidator.ALLOW_ALL_SCHEMES); + setUp(); + long options = + UrlValidator.ALLOW_2_SLASHES + + UrlValidator.ALLOW_ALL_SCHEMES + + UrlValidator.NO_FRAGMENTS; + + testIsValid(testUrlPartsOptions, options); + } + + @Test + public void testIsValidScheme() { + if (printStatus) { + System.out.print("\n testIsValidScheme() "); + } + //UrlValidator urlVal = new UrlValidator(schemes,false,false,false); + UrlValidator urlVal = new UrlValidator(schemes, 0); + for (ResultPair testPair : testScheme) { + boolean result = urlVal.isValidScheme(testPair.item); + assertEquals(testPair.item, testPair.valid, result); + if (printStatus) { + if (result == testPair.valid) { + System.out.print('.'); + } else { + System.out.print('X'); + } + } + } + if (printStatus) { + System.out.println(); + } + + } + + /** + * Create set of tests by taking the testUrlXXX arrays and + * running through all possible permutations of their combinations. + * + * @param testObjects Used to create a url. + */ + public void testIsValid(Object[] testObjects, long options) { + UrlValidator urlVal = new UrlValidator(null, null, options); + assertTrue(urlVal.isValid("http://www.google.com")); + assertTrue(urlVal.isValid("http://www.google.com/")); + int statusPerLine = 60; + int printed = 0; + if (printIndex) { + statusPerLine = 6; + } + do { + StringBuilder testBuffer = new StringBuilder(); + boolean expected = true; + for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) { + int index = testPartsIndex[testPartsIndexIndex]; + ResultPair[] part = (ResultPair[]) testObjects[testPartsIndexIndex]; + testBuffer.append(part[index].item); + expected &= part[index].valid; + } + String url = testBuffer.toString(); + boolean result = urlVal.isValid(url); + assertEquals(url, expected, result); + if (printStatus) { + if (printIndex) { + System.out.print(testPartsIndextoString()); + } else { + if (result == expected) { + System.out.print('.'); + } else { + System.out.print('X'); + } + } + printed++; + if (printed == statusPerLine) { + System.out.println(); + printed = 0; + } + } + } while (incrementTestPartsIndex(testPartsIndex, testObjects)); + if (printStatus) { + System.out.println(); + } + } + + @Test + public void testValidator202() { + String[] schemes = {"http","https"}; + UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS); + assertTrue(urlValidator.isValid("http://l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.org")); + } + + @Test + public void testValidator204() { + String[] schemes = {"http","https"}; + UrlValidator urlValidator = new UrlValidator(schemes); + assertTrue(urlValidator.isValid("http://tech.yahoo.com/rc/desktops/102;_ylt=Ao8yevQHlZ4On0O3ZJGXLEQFLZA5")); + } + + @Test + public void testValidator218() { + UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES); + assertTrue("parentheses should be valid in URLs", + validator.isValid("http://somewhere.com/pathxyz/file(1).html")); + } + + @Test + public void testValidator235() { + String version = System.getProperty("java.version"); + if (version.compareTo("1.6") < 0) { + System.out.println("Cannot run Unicode IDN tests"); + return; // Cannot run the test + } + UrlValidator validator = new UrlValidator(); + assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("http://xn--d1abbgf6aiiy.xn--p1ai")); + assertTrue("президент.рф should validate", validator.isValid("http://президент.рф")); + assertTrue("www.b\u00fccher.ch should validate", validator.isValid("http://www.b\u00fccher.ch")); + assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("http://www.\uFFFD.ch")); + assertTrue("www.b\u00fccher.ch should validate", validator.isValid("ftp://www.b\u00fccher.ch")); + assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("ftp://www.\uFFFD.ch")); + } + + @Test + public void testValidator248() { + RegexValidator regex = new RegexValidator(new String[] {"localhost", ".*\\.my-testing"}); + UrlValidator validator = new UrlValidator(regex, 0); + + assertTrue("localhost URL should validate", + validator.isValid("http://localhost/test/index.html")); + assertTrue("first.my-testing should validate", + validator.isValid("http://first.my-testing/test/index.html")); + assertTrue("sup3r.my-testing should validate", + validator.isValid("http://sup3r.my-testing/test/index.html")); + + assertFalse("broke.my-test should not validate", + validator.isValid("http://broke.my-test/test/index.html")); + + assertTrue("www.apache.org should still validate", + validator.isValid("http://www.apache.org/test/index.html")); + + // Now check using options + validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); + + assertTrue("localhost URL should validate", + validator.isValid("http://localhost/test/index.html")); + + assertTrue("machinename URL should validate", + validator.isValid("http://machinename/test/index.html")); + + assertTrue("www.apache.org should still validate", + validator.isValid("http://www.apache.org/test/index.html")); + } + + @Test + public void testValidator288() { + UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); + + assertTrue("hostname should validate", + validator.isValid("http://hostname")); + + assertTrue("hostname with path should validate", + validator.isValid("http://hostname/test/index.html")); + + assertTrue("localhost URL should validate", + validator.isValid("http://localhost/test/index.html")); + + assertFalse("first.my-testing should not validate", + validator.isValid("http://first.my-testing/test/index.html")); + + assertFalse("broke.hostname should not validate", + validator.isValid("http://broke.hostname/test/index.html")); + + assertTrue("www.apache.org should still validate", + validator.isValid("http://www.apache.org/test/index.html")); + + // Turn it off, and check + validator = new UrlValidator(0); + + assertFalse("hostname should no longer validate", + validator.isValid("http://hostname")); + + assertFalse("localhost URL should no longer validate", + validator.isValid("http://localhost/test/index.html")); + + assertTrue("www.apache.org should still validate", + validator.isValid("http://www.apache.org/test/index.html")); + } + + @Test + public void testValidator276() { + // file:// isn't allowed by default + UrlValidator validator = new UrlValidator(); + + assertTrue("http://apache.org/ should be allowed by default", + validator.isValid("http://www.apache.org/test/index.html")); + + assertFalse("file:///c:/ shouldn't be allowed by default", + validator.isValid("file:///C:/some.file")); + + assertFalse("file:///c:\\ shouldn't be allowed by default", + validator.isValid("file:///C:\\some.file")); + + assertFalse("file:///etc/ shouldn't be allowed by default", + validator.isValid("file:///etc/hosts")); + + assertFalse("file://localhost/etc/ shouldn't be allowed by default", + validator.isValid("file://localhost/etc/hosts")); + + assertFalse("file://localhost/c:/ shouldn't be allowed by default", + validator.isValid("file://localhost/c:/some.file")); + + // Turn it on, and check + // Note - we need to enable local urls when working with file: + validator = new UrlValidator(new String[] {"http","file"}, UrlValidator.ALLOW_LOCAL_URLS); + + assertTrue("http://apache.org/ should be allowed by default", + validator.isValid("http://www.apache.org/test/index.html")); + + assertTrue("file:///c:/ should now be allowed", + validator.isValid("file:///C:/some.file")); + + assertFalse("file:///c:\\ should not be allowed", // Only allow forward slashes + validator.isValid("file:///C:\\some.file")); + + assertTrue("file:///etc/ should now be allowed", + validator.isValid("file:///etc/hosts")); + + assertTrue("file://localhost/etc/ should now be allowed", + validator.isValid("file://localhost/etc/hosts")); + + assertTrue("file://localhost/c:/ should now be allowed", + validator.isValid("file://localhost/c:/some.file")); + + // These are never valid + assertFalse("file://c:/ shouldn't ever be allowed, needs file:///c:/", + validator.isValid("file://C:/some.file")); + + assertFalse("file://c:\\ shouldn't ever be allowed, needs file:///c:/", + validator.isValid("file://C:\\some.file")); + } + + @Test + public void testValidator391OK() { + String[] schemes = {"file"}; + UrlValidator urlValidator = new UrlValidator(schemes); + assertTrue(urlValidator.isValid("file:///C:/path/to/dir/")); + } + + @Test + public void testValidator391FAILS() { + String[] schemes = {"file"}; + UrlValidator urlValidator = new UrlValidator(schemes); + assertTrue(urlValidator.isValid("file:/C:/path/to/dir/")); + } + + @Test + public void testValidator309() { + UrlValidator urlValidator = new UrlValidator(); + assertTrue(urlValidator.isValid("http://sample.ondemand.com/")); + assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/")); + assertTrue(urlValidator.isValid("httpS://SAMPLE.ONEMAND.COM/")); + urlValidator = new UrlValidator(new String[] {"HTTP","HTTPS"}); + assertTrue(urlValidator.isValid("http://sample.ondemand.com/")); + assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/")); + assertTrue(urlValidator.isValid("httpS://SAMPLE.ONEMAND.COM/")); + } + + @Test + public void testValidator339(){ + UrlValidator urlValidator = new UrlValidator(); + assertTrue(urlValidator.isValid("http://www.cnn.com/WORLD/?hpt=sitenav")); // without + assertTrue(urlValidator.isValid("http://www.cnn.com./WORLD/?hpt=sitenav")); // with + assertFalse(urlValidator.isValid("http://www.cnn.com../")); // doubly dotty + assertFalse(urlValidator.isValid("http://www.cnn.invalid/")); + assertFalse(urlValidator.isValid("http://www.cnn.invalid./")); // check . does not affect invalid domains + } + + @Test + public void testValidator339IDN(){ + UrlValidator urlValidator = new UrlValidator(); + assertTrue(urlValidator.isValid("http://президент.рф/WORLD/?hpt=sitenav")); // without + assertTrue(urlValidator.isValid("http://президент.рф./WORLD/?hpt=sitenav")); // with + assertFalse(urlValidator.isValid("http://президент.рф..../")); // very dotty + assertFalse(urlValidator.isValid("http://президент.рф.../")); // triply dotty + assertFalse(urlValidator.isValid("http://президент.рф../")); // doubly dotty + } + + @Test + public void testValidator342(){ + UrlValidator urlValidator = new UrlValidator(); + assertTrue(urlValidator.isValid("http://example.rocks/")); + assertTrue(urlValidator.isValid("http://example.rocks")); + } + + @Test + public void testValidator411(){ + UrlValidator urlValidator = new UrlValidator(); + assertTrue(urlValidator.isValid("http://example.rocks:/")); + assertTrue(urlValidator.isValid("http://example.rocks:0/")); + assertTrue(urlValidator.isValid("http://example.rocks:65535/")); + assertFalse(urlValidator.isValid("http://example.rocks:65536/")); + assertFalse(urlValidator.isValid("http://example.rocks:100000/")); + } + + @Test + public void testValidator464() { + String[] schemes = {"file"}; + UrlValidator urlValidator = new UrlValidator(schemes); + String fileNAK = "file://bad ^ domain.com/label/test"; + assertFalse(fileNAK, urlValidator.isValid(fileNAK)); + } + + @Test + public void testValidator452(){ + UrlValidator urlValidator = new UrlValidator(); + assertTrue(urlValidator.isValid("http://[::FFFF:129.144.52.38]:80/index.html")); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidator473_1() { // reject null DomainValidator + new UrlValidator(new String[]{}, null, 0L, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidator473_2() { // reject null DomainValidator with mismatched allowLocal + List