File: AUTHTest.java

package info (click to toggle)
libjgroups-java 2.12.2.Final-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,712 kB
  • sloc: java: 109,098; xml: 9,423; sh: 149; makefile: 2
file content (151 lines) | stat: -rw-r--r-- 4,538 bytes parent folder | download | duplicates (5)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package org.jgroups.protocols;


import org.jgroups.Global;
import org.jgroups.auth.MD5Token;
import org.jgroups.auth.SimpleToken;
import org.testng.annotations.Test;

/**
 * A set of JUnit tests for the AUTH protocol
 * @author Chris Mills
 */
@Test(groups=Global.FUNCTIONAL,sequential=false)
public class AUTHTest {

    /**
     * Creates two SimpleToken objects with identical auth_values and authenticates one against the other
     * Test fails if an exception is thrown or authentication fails
     */
    public static void testSimpleToken() {
        SimpleToken token1=new SimpleToken();
        token1.setAuthValue("chris");
        SimpleToken token2=new SimpleToken();
        token2.setAuthValue("chris");
        assert token1.authenticate(token2, null);
    }

    /**
     * Creates two SimpleToken objects with different auth_values and authenticates one against the other
     * <p/>
     * Test fails if an exception is thrown or authentication passes
     */
    public static void testSimpleTokenMismatch() {
        SimpleToken token1=new SimpleToken();
        token1.setAuthValue("chris");
        SimpleToken token2=new SimpleToken();
        token2.setAuthValue("chrismills");
        assert !token1.authenticate(token2, null);
    }

    /**
     * Creates two MD5Token objects with identical auth_values and authenticates one against the other
     * <p/>
     * Uses an MD5 hash type
     * <p/>
     * Test fails if an exception is thrown or authentication fails
     */
    public static void testMD5Token() {
        MD5Token token1=new MD5Token();
        token1.setAuthValue("chris");
        token1.setHashType("MD5");

        MD5Token token2=new MD5Token();
        token2.setAuthValue("chris");
        token2.setHashType("MD5");

        assert token1.authenticate(token2, null);
    }

    /**
     * Creates two MD5Token objects with different auth_values and authenticates one against the other
     * <p/>
     * Uses an MD5 hash type
     * <p/>
     * Test fails if an exception is thrown or authentication passes
     */
    public static void testMD5TokenMismatch() {
        MD5Token token1=new MD5Token();
        token1.setAuthValue("chris");
        token1.setHashType("MD5");

        MD5Token token2=new MD5Token();
        token2.setAuthValue("chrismills");
        token2.setHashType("MD5");

        assert !token1.authenticate(token2, null);
    }

    /**
     * Creates two MD5Token objects with identical auth_values and authenticates one against the other
     * <p/>
     * Uses an SHA hash type
     * <p/>
     * Test fails if an exception is thrown or authentication fails
     */
    public static void testSHAToken() {
        MD5Token token1=new MD5Token();
        token1.setAuthValue("chris");
        token1.setHashType("SHA");

        MD5Token token2=new MD5Token();
        token2.setAuthValue("chris");
        token2.setHashType("SHA");

        assert token1.authenticate(token2, null);
    }

    /**
     * Creates two MD5Token objects with different auth_values and authenticates one against the other
     * <p/>
     * Uses an SHA hash type
     * <p/>
     * Test fails if an exception is thrown or authentication passes
     */
    public static void testSHATokenMismatch() {
        MD5Token token1=new MD5Token();
        token1.setAuthValue("chris");
        token1.setHashType("SHA");

        MD5Token token2=new MD5Token();
        token2.setAuthValue("chrismills");
        token2.setHashType("SHA");

        assert !token1.authenticate(token2, null);
    }

    /**
     * Test to create an AuthHeader object and set and get the Token object
     * <p/>
     * Fails if an exception is thrown or the set and get don't equal the same object
     */
    public static void testAuthHeader() {
        SimpleToken token1=new SimpleToken();
        token1.setAuthValue("chris");

        AuthHeader header=new AuthHeader();
        header.setToken(token1);

        assert token1 == header.getToken();
    }

    /**
     * Test to create an AuthHeader object and set and get the Token object
     * <p/>
     * Fails if an exception is thrown or the set and get equal the same object
     */
    public static void testAuthHeaderDifferent() {
        SimpleToken token1=new SimpleToken();
        token1.setAuthValue("chris");

        SimpleToken token2=new SimpleToken();
        token2.setAuthValue("chris");

        AuthHeader header=new AuthHeader();
        header.setToken(token1);

        assert !(token2 == header.getToken());
    }


}