summaryrefslogtreecommitdiff
blob: 7ab7b2ad20ab1f2f90f4cd8089a85dca4e78db15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
From 60d93af35887e53677be5a0f95591489c2683c73 Mon Sep 17 00:00:00 2001
From: Kent Fredric <kentnl@gentoo.org>
Date: Wed, 13 Dec 2017 18:42:56 +1300
Subject: Remove test interactivity

Pass configuration by enviroment variables and don't prompt.
---
 test.pl | 82 ++++++++++++++++-------------------------------------------------
 1 file changed, 20 insertions(+), 62 deletions(-)

diff --git a/test.pl b/test.pl
index 369bc30..e9f7ae2 100644
--- a/test.pl
+++ b/test.pl
@@ -5,14 +5,8 @@
 
 use Test::More tests => 32;
 #use Test::More qw/no_plan/;
-use ExtUtils::MakeMaker qw/prompt/;
 use Carp;
 use Cwd;
-my $HAVE_Term_ReadKey = 0;
-eval "use Term::ReadKey";
-if(!$@) {
-    $HAVE_Term_ReadKey = 1
-}
 
 use vars qw/$ROUTER $PASSWD $LOGIN $S $EN_PASS $PASSCODE/;
 
@@ -161,18 +155,9 @@ END { cleanup() };
 
 sub cleanup {
     return unless -f "input.log" || -f "dump.log";
-
-    print <<EOB;
-
-Would you like to delete the test logs? They will contain
-security info like your login and passwords. If you ran
-into problems and wish to investigate, you can save them
-and manually delete them later.
-EOB
-
     my $dir = cwd();
 
-    my $ans = prompt("Delete logs", "y");
+    my $ans = "y";
     if ($ans eq "y") {
 	print "Deleting logs in $dir...";
 	unlink "input.log" or warn "Can't delete input.log! $!";
@@ -183,53 +168,26 @@ EOB
     }
 }
 
-sub get_login {
-    print <<EOB;
-
-Net::Telnet::Cisco needs to log into a router to
-perform it\'s full suite of tests. To log in, we
-need a test router, a login, a password, an
-optional enable password, and an optional
-SecurID/TACACS PASSCODE.
-
-To skip these tests, hit "return".
-
-EOB
-
-    $ROUTER   = prompt("Router:", $ROUTER) or return;
-    $LOGIN    = prompt("Login:", $LOGIN) or return;
-    $PASSWD   = passprompt("Password:", $PASSWD) or return;
-    $EN_PASS  = passprompt("Enable password [optional]:", $EN_PASS);
-    $PASSCODE = passprompt("SecurID/TACACS PASSCODE [optional]:", $PASSCODE);
+sub maskpass {
+    return 'not set' unless defined $_[0];
+    return ( '*' x ( length $_[0] ) ) . ' [masked]';
 }
 
+sub get_login {
+    $ROUTER = $ENV{CISCO_TEST_ROUTER}   or return;
+    $LOGIN  = $ENV{CISCO_TEST_LOGIN}    or return;
+    $PASSWD = $ENV{CISCO_TEST_PASSWORD} or return;
+    $EN_PASS  = $ENV{CISCO_TEST_ENABLE_PASSWORD};
+    $PASSCODE = $ENV{CISCO_TEST_PASSCODE};
+
+    printf STDERR
+      <<EOB, $ROUTER, $LOGIN, maskpass($PASSWD), maskpass($EN_PASS), maskpass($PASSCODE);
+Using the following configuration for testing:
+                    Router: %s
+                     Login: %s
+                  Password: %s
+           Enable Password: %s
+  SecureID/TACACS PASSCODE: %s
 
-# Lifted from ExtUtils::MakeMaker.
-#
-# If the user has Term::ReadKey, we can hide any passwords
-# they type from shoulder-surfing attacks.
-#
-# Args: "Question for user", "optional default answer"
-sub passprompt ($;$) {
-    my($mess,$def)=@_;
-    $ISA_TTY = -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)) ;   # Pipe?
-    Carp::confess("prompt function called without an argument") unless defined $mess;
-    my $dispdef = defined $def ? "[$def] " : " ";
-    $def = defined $def ? $def : "";
-    my $ans;
-    local $|=1;
-    print "$mess $dispdef";
-    if ($ISA_TTY) {
-	if ( $Term::ReadKey::VERSION ) {
-	    ReadMode( 'noecho' );
-	    chomp($ans = ReadLine(0));
-	    ReadMode( 'normal' );
-	    print "\n";
-	} else {
-	    chomp($ans = <STDIN>);
-	}
-    } else {
-        print "$def\n";
-    }
-    return ($ans ne '') ? $ans : $def;
+EOB
 }
-- 
2.14.3