1+ /*
2+ * Copyright (C) 2018 Google Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org .oidc .msg .validator ;
18+
19+ import com .auth0 .jwt .exceptions .oicmsg_exceptions .DeserializationNotPossible ;
20+ import com .auth0 .jwt .exceptions .oicmsg_exceptions .SerializationNotPossible ;
21+ import com .auth0 .jwt .exceptions .oicmsg_exceptions .ValueError ;
22+ import com .auth0 .msg .Key ;
23+ import java .util .Map ;
24+ import org .junit .Assert ;
25+ import org .junit .Before ;
26+ import org .junit .Test ;
27+ import org .oidc .msg .InvalidClaimException ;
28+
29+ /**
30+ * Unit tests for {@link KeyClaimValidator}.
31+ */
32+ public class KeyClaimValidatorTest extends BaseClaimValidatorTest <KeyClaimValidator > {
33+
34+ @ Before
35+ public void setup () {
36+ validator = new KeyClaimValidator ();
37+ }
38+
39+ @ Test
40+ public void testValidValue () throws InvalidClaimException {
41+ Assert .assertTrue (validator .validate (new MockKey ()) instanceof Key );
42+ }
43+
44+ @ Test (expected = InvalidClaimException .class )
45+ public void testInvalidValue () throws InvalidClaimException {
46+ validator .validate ("somethingelse" );
47+ }
48+
49+ class MockKey extends Key {
50+
51+ @ Override
52+ public void deserialize () throws DeserializationNotPossible {
53+ }
54+
55+ @ Override
56+ public java .security .Key getKey (Boolean arg0 ) throws ValueError {
57+ return null ;
58+ }
59+
60+ @ Override
61+ public boolean isPrivateKey () {
62+ return false ;
63+ }
64+
65+ @ Override
66+ public Map <String , Object > serialize (boolean arg0 ) throws SerializationNotPossible {
67+ return null ;
68+ }
69+ }
70+ }
0 commit comments