#!/usr/bin/perl -w
#
# Written by Roland Schemers
# Copyright 2003 Board of Trustees, Leland Stanford Jr. University
#
# See LICENSE for licensing terms.

use strict;

sub last_used_test {

    my $WEBAUTH_TOKEN_LASTUSED = $ENV{'WEBAUTH_TOKEN_LASTUSED'};
    my $time = time();
    my $low = $time-10;
    my $high = $time+10;
    print "<hr>\n";

    &begin_tests("Performing LASTUSED test");

    &do_test("WEBAUTH_TOKEN_LASTUSED",
	     ($WEBAUTH_TOKEN_LASTUSED > $low && 
	     $WEBAUTH_TOKEN_LASTUSED < $high),
	     "set  to <b>".scalar(localtime($WEBAUTH_TOKEN_LASTUSED))."</b>",
	     "not within the acceptable time window!");
    &end_tests;
    print "<hr>\n";
}

my $REMOTE_USER = $ENV{'REMOTE_USER'};
my $WTL = $ENV{'WEBAUTH_TOKEN_LASTUSED'};
my ($prev) = $ENV{'QUERY_STRING'} =~ /prev=(\d+)/;

require 'util.pl';

print "Content-type: text/html\n\n";

print "<html>\n";

test_title(10, "testing inactive-expire");

print<<EOS;

You are accessing a webauth-protected page as the user: $REMOTE_USER<br>
<br>
This test is to make sure WEBAUTH_TOKEN_LASTUSED is getting updated,
and that inactive timeouts are working. 
<br>
<br>
EOS

if ($prev) {
    my $ps = scalar(localtime($prev));

print<<EOS;
The previous value of WEBAUTH_TOKEN_LASTUSED was $ps ($prev).
<br>
<br>
EOS
}


print<<EOS;
Click <a href="/tests/auth/test10?prev=$WTL">here</a> to re-run the test.
If you wait for less then 20 seconds, you'll get taken back to this
page. If you wait for more then 20 seconds, you should end up back
at the webkdc login page.
<br>
EOS

&return_links;

&last_used_test;

&dump_stuff;

print "</html>";

