Mercurial > hg > icedtea8-forest > jdk
changeset 12449:9561afc12df8 jdk8u121-b12
8059212: Modify sun/security/smartcardio manual regression tests so that they do not just fail if no cardreader found
Reviewed-by: mullan
author | igerasim |
---|---|
date | Wed, 30 Nov 2016 13:46:05 +0300 |
parents | 0cb423d5df20 |
children | aac4a6c5299c |
files | test/sun/security/smartcardio/TestChannel.java test/sun/security/smartcardio/TestConnect.java test/sun/security/smartcardio/TestConnectAgain.java test/sun/security/smartcardio/TestControl.java test/sun/security/smartcardio/TestDefault.java test/sun/security/smartcardio/TestDirect.java test/sun/security/smartcardio/TestExclusive.java test/sun/security/smartcardio/TestMultiplePresent.java test/sun/security/smartcardio/TestPresent.java test/sun/security/smartcardio/TestTransmit.java test/sun/security/smartcardio/Utils.java |
diffstat | 11 files changed, 115 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/test/sun/security/smartcardio/TestChannel.java Mon Dec 05 10:07:47 2016 -0800 +++ b/test/sun/security/smartcardio/TestChannel.java Wed Nov 30 13:46:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -46,6 +46,11 @@ public static void main(String[] args) throws Exception { CardTerminal terminal = getTerminal(args); + if (terminal == null) { + System.out.println("Skipping the test: " + + "no card terminals available"); + return; + } // establish a connection with the card Card card = terminal.connect("T=0");
--- a/test/sun/security/smartcardio/TestConnect.java Mon Dec 05 10:07:47 2016 -0800 +++ b/test/sun/security/smartcardio/TestConnect.java Wed Nov 30 13:46:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,23 +39,12 @@ public class TestConnect extends Utils { public static void main(String[] args) throws Exception { - TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null, "SunPCSC"); - System.out.println(factory); - - List<CardTerminal> terminals = factory.terminals().list(); - System.out.println("Terminals: " + terminals); - if (terminals.isEmpty()) { - throw new Exception("No card terminals available"); + CardTerminal terminal = getTerminal(args, "SunPCSC"); + if (terminal == null) { + System.out.println("Skipping the test: " + + "no card terminals available"); + return; } - CardTerminal terminal = terminals.get(0); - - if (terminal.isCardPresent() == false) { - System.out.println("*** Insert card"); - if (terminal.waitForCardPresent(20 * 1000) == false) { - throw new Exception("no card available"); - } - } - System.out.println("card present: " + terminal.isCardPresent()); Card card = terminal.connect("*"); System.out.println("card: " + card);
--- a/test/sun/security/smartcardio/TestConnectAgain.java Mon Dec 05 10:07:47 2016 -0800 +++ b/test/sun/security/smartcardio/TestConnectAgain.java Wed Nov 30 13:46:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,6 +39,11 @@ public static void main(String[] args) throws Exception { CardTerminal terminal = getTerminal(args); + if (terminal == null) { + System.out.println("Skipping the test: " + + "no card terminals available"); + return; + } Card card = terminal.connect("T=0"); CardChannel channel = card.getBasicChannel();
--- a/test/sun/security/smartcardio/TestControl.java Mon Dec 05 10:07:47 2016 -0800 +++ b/test/sun/security/smartcardio/TestControl.java Wed Nov 30 13:46:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,6 +40,11 @@ public static void main(String[] args) throws Exception { CardTerminal terminal = getTerminal(args); + if (terminal == null) { + System.out.println("Skipping the test: " + + "no card terminals available"); + return; + } // establish a connection with the card Card card = terminal.connect("T=0");
--- a/test/sun/security/smartcardio/TestDefault.java Mon Dec 05 10:07:47 2016 -0800 +++ b/test/sun/security/smartcardio/TestDefault.java Wed Nov 30 13:46:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,10 +40,12 @@ TerminalFactory factory = TerminalFactory.getDefault(); System.out.println("Type: " + factory.getType()); List<CardTerminal> terminals = factory.terminals().list(); + if (terminals.isEmpty()) { + System.out.println("Skipping the test: " + + "no card terminals available"); + return; + } System.out.println("Terminals: " + terminals); - if (terminals.isEmpty()) { - throw new Exception("no terminals"); - } System.out.println("OK."); }
--- a/test/sun/security/smartcardio/TestDirect.java Mon Dec 05 10:07:47 2016 -0800 +++ b/test/sun/security/smartcardio/TestDirect.java Wed Nov 30 13:46:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,10 +40,12 @@ public static void main(String[] args) throws Exception { TerminalFactory terminalFactory = TerminalFactory.getDefault(); List<CardTerminal> cardTerminals = terminalFactory.terminals().list(); + if (cardTerminals.isEmpty()) { + System.out.println("Skipping the test: " + + "no card terminals available"); + return; + } System.out.println("Terminals: " + cardTerminals); - if (cardTerminals.isEmpty()) { - throw new Exception("No card terminals available"); - } CardTerminal cardTerminal = cardTerminals.get(0); Card card = cardTerminal.connect("DIRECT"); card.disconnect(true);
--- a/test/sun/security/smartcardio/TestExclusive.java Mon Dec 05 10:07:47 2016 -0800 +++ b/test/sun/security/smartcardio/TestExclusive.java Wed Nov 30 13:46:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,6 +44,11 @@ public static void main(String[] args) throws Exception { CardTerminal terminal = getTerminal(args); + if (terminal == null) { + System.out.println("Skipping the test: " + + "no card terminals available"); + return; + } // establish a connection with the card Card card = terminal.connect("T=0");
--- a/test/sun/security/smartcardio/TestMultiplePresent.java Mon Dec 05 10:07:47 2016 -0800 +++ b/test/sun/security/smartcardio/TestMultiplePresent.java Wed Nov 30 13:46:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,7 +40,12 @@ public static void main(String[] args) throws Exception { Utils.setLibrary(args); - TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null); + TerminalFactory factory = Utils.getTerminalFactory(null); + if (factory == null) { + System.out.println("Skipping the test: " + + "no card terminals available"); + return; + } System.out.println(factory); CardTerminals terminals = factory.terminals(); @@ -49,7 +54,9 @@ boolean multipleReaders = true; if (list.size() < 2) { if (list.isEmpty()) { - throw new Exception("no terminals"); + System.out.println("Skipping the test: " + + "no card terminals available"); + return; } System.out.println("Only one reader present, using simplified test"); multipleReaders = false;
--- a/test/sun/security/smartcardio/TestPresent.java Mon Dec 05 10:07:47 2016 -0800 +++ b/test/sun/security/smartcardio/TestPresent.java Wed Nov 30 13:46:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,7 +34,7 @@ import javax.smartcardio.CardTerminal; import javax.smartcardio.TerminalFactory; -public class TestPresent { +public class TestPresent extends Utils { private static class Timer { private long time = System.currentTimeMillis(); @@ -66,15 +66,12 @@ } public static void main(String[] args) throws Exception { - TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null); - System.out.println(factory); - - List<CardTerminal> terminals = factory.terminals().list(); - System.out.println("Terminals: " + terminals); - if (terminals.isEmpty()) { - throw new Exception("No card terminals available"); + CardTerminal terminal = getTerminal(args); + if (terminal == null) { + System.out.println("Skipping the test: " + + "no card terminals available"); + return; } - CardTerminal terminal = terminals.get(0); while (terminal.isCardPresent()) { System.out.println("*** Remove card!");
--- a/test/sun/security/smartcardio/TestTransmit.java Mon Dec 05 10:07:47 2016 -0800 +++ b/test/sun/security/smartcardio/TestTransmit.java Wed Nov 30 13:46:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -48,6 +48,11 @@ public static void main(String[] args) throws Exception { CardTerminal terminal = getTerminal(args); + if (terminal == null) { + System.out.println("Skipping the test: " + + "no card terminals available"); + return; + } Card card = terminal.connect("T=0"); CardChannel channel = card.getBasicChannel();
--- a/test/sun/security/smartcardio/Utils.java Mon Dec 05 10:07:47 2016 -0800 +++ b/test/sun/security/smartcardio/Utils.java Wed Nov 30 13:46:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,7 @@ import java.io.StringReader; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.List; import javax.smartcardio.CardTerminal; @@ -43,26 +44,59 @@ } } + static TerminalFactory getTerminalFactory(String provName) throws Exception { + try { + TerminalFactory factory = (provName == null) + ? TerminalFactory.getInstance("PC/SC", null) + : TerminalFactory.getInstance("PC/SC", null, provName); + System.out.println(factory); + return factory; + } catch (NoSuchAlgorithmException e) { + Throwable cause = e.getCause(); + if (cause != null && cause.getMessage().startsWith("PC/SC not available")) { + return null; + } + throw e; + } + } + static CardTerminal getTerminal(String[] args) throws Exception { + return getTerminal(args, null); + } + + static CardTerminal getTerminal(String[] args, String provider) throws Exception { setLibrary(args); - TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null); - System.out.println(factory); + try { + TerminalFactory factory = (provider == null) + ? TerminalFactory.getInstance("PC/SC", null) + : TerminalFactory.getInstance("PC/SC", null, provider); + System.out.println(factory); + + List<CardTerminal> terminals = factory.terminals().list(); + System.out.println("Terminals: " + terminals); + if (terminals.isEmpty()) { + return null; + } + CardTerminal terminal = terminals.get(0); - List<CardTerminal> terminals = factory.terminals().list(); - System.out.println("Terminals: " + terminals); - if (terminals.isEmpty()) { - throw new Exception("No card terminals available"); + if (terminal.isCardPresent() == false) { + System.out.println("*** Insert card"); + if (terminal.waitForCardPresent(20 * 1000) == false) { + throw new Exception("no card available"); + } + } + System.out.println("card present: " + terminal.isCardPresent()); + + return terminal; + + } catch (NoSuchAlgorithmException e) { + Throwable cause = e.getCause(); + if (cause != null && cause.getMessage().startsWith("PC/SC not available")) { + return null; + } + throw e; } - CardTerminal terminal = terminals.get(0); - - if (terminal.isCardPresent() == false) { - System.out.println("*** Insert card"); - if (terminal.waitForCardPresent(20 * 1000) == false) { - throw new Exception("no card available"); - } - } - return terminal; } static final byte[] C1 = parse("00 A4 04 00 07 A0 00 00 00 62 81 01 00");