|
| 1 | +/* |
| 2 | + Copyright (c) Microsoft Open Technologies, Inc. |
| 3 | + All Rights Reserved |
| 4 | + Apache License 2.0 |
| 5 | +
|
| 6 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + you may not use this file except in compliance with the License. |
| 8 | + You may obtain a copy of the License at |
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | + Unless required by applicable law or agreed to in writing, software |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + See the License for the specific language governing permissions and |
| 15 | + limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +'use strict'; |
| 19 | + |
| 20 | +var Metadata = require('../lib/metadata').Metadata; |
| 21 | + |
| 22 | +/* |
| 23 | + ======== A Handy Little Nodeunit Reference ======== |
| 24 | + https://github.com/caolan/nodeunit |
| 25 | +
|
| 26 | + Test methods: |
| 27 | + test.expect(numAssertions) |
| 28 | + test.done() |
| 29 | + Test assertions: |
| 30 | + test.ok(value, [message]) |
| 31 | + test.equal(actual, expected, [message]) |
| 32 | + test.notEqual(actual, expected, [message]) |
| 33 | + test.deepEqual(actual, expected, [message]) |
| 34 | + test.notDeepEqual(actual, expected, [message]) |
| 35 | + test.strictEqual(actual, expected, [message]) |
| 36 | + test.notStrictEqual(actual, expected, [message]) |
| 37 | + test.throws(block, [error], [message]) |
| 38 | + test.doesNotThrow(block, [error], [message]) |
| 39 | + test.ifError(value) |
| 40 | + */ |
| 41 | + |
| 42 | +var wsfed_metadataUrl = 'https://login.windows.net/GraphDir1.OnMicrosoft.com/federationmetadata/2007-06/federationmetadata.xml'; |
| 43 | +var oidc_metadataUrl = 'https://login.microsoftonline.com/common/.well-known/openid-configuration'; |
| 44 | + |
| 45 | +exports['metadata'] = { |
| 46 | + |
| 47 | + 'metadata has correct URL and option': function(test) { |
| 48 | + test.expect(1); |
| 49 | + // tests here |
| 50 | + |
| 51 | + test.doesNotThrow( |
| 52 | + function() { |
| 53 | + new Metadata(wsfed_metadataUrl, 'wsfed'); |
| 54 | + }, |
| 55 | + Error, |
| 56 | + 'Metadata method should not fail with url present' |
| 57 | + ); |
| 58 | + |
| 59 | + test.done(); |
| 60 | + }, |
| 61 | + 'missing URL': function(test) { |
| 62 | + test.expect(1); |
| 63 | + // tests here |
| 64 | + |
| 65 | + test.throws( |
| 66 | + function() { |
| 67 | + new Metadata(); |
| 68 | + }, |
| 69 | + Error, |
| 70 | + 'Metadata method should fail when url not present' |
| 71 | + ); |
| 72 | + |
| 73 | + test.done(); |
| 74 | + }, |
| 75 | + |
| 76 | + 'missing option': function(test) { |
| 77 | + test.expect(1); |
| 78 | + // tests here |
| 79 | + |
| 80 | + test.throws( |
| 81 | + function() { |
| 82 | + new Metadata(wsfed_metadataUrl); |
| 83 | + }, |
| 84 | + Error, |
| 85 | + 'Metadata method should fail when url not present' |
| 86 | + ); |
| 87 | + |
| 88 | + test.done(); |
| 89 | + }, |
| 90 | + |
| 91 | + 'fetch metadata for WSFed and SAML': function(test) { |
| 92 | + test.expect(7); |
| 93 | + // tests here |
| 94 | + |
| 95 | + test.doesNotThrow( |
| 96 | + function() { |
| 97 | + var m = new Metadata(wsfed_metadataUrl, "wsfed"); // either wsfed or saml works here. It just indicates to parse XML vs. JSON |
| 98 | + m.fetch(function(err) { |
| 99 | + test.ifError(err, 'method had error before testing properties'); |
| 100 | + test.ok(m.saml.certs.length > 0, 'fetch should obtain 1 or more saml x509 certificates'); |
| 101 | + test.ok(m.saml.loginEndpoint, 'fetch should obtain saml login endpoint'); |
| 102 | + test.ok(m.saml.logoutEndpoint, 'fetch should obtain saml logout endpoint'); |
| 103 | + test.ok(m.wsfed.certs.length > 0, 'fetch should obtain 1 or more wsfed x509 certificates'); |
| 104 | + test.ok(m.wsfed.loginEndpoint, 'fetch should obtain wsfedlogin endpoint'); |
| 105 | + }); |
| 106 | + }, |
| 107 | + Error, |
| 108 | + 'WSFed and SAML should not fail with url present' |
| 109 | + ); |
| 110 | + test.done(); |
| 111 | + }, |
| 112 | + |
| 113 | + 'fetch metadata for OIDC': function(test) { |
| 114 | + test.expect(7); |
| 115 | + // tests here |
| 116 | + |
| 117 | + test.doesNotThrow( |
| 118 | + function() { |
| 119 | + var m = new Metadata(oidc_metadataUrl, "oidc"); // this indicates to parse JSON vs. XML |
| 120 | + m.fetch(function(err) { |
| 121 | + test.ifError(err, 'method had error before testing properties'); |
| 122 | + test.ok(m.oidc.certs.length > 0, 'fetch should obtain 1 or more saml x509 certificates'); |
| 123 | + test.ok(m.oidc.loginEndpoint, 'fetch should obtain saml login endpoint'); |
| 124 | + test.ok(m.oidc.logoutEndpoint, 'fetch should obtain saml logout endpoint'); |
| 125 | + }); |
| 126 | + }, |
| 127 | + Error, |
| 128 | + 'Open ID Connect should not fail with url present' |
| 129 | + ); |
| 130 | + test.done(); |
| 131 | + } |
| 132 | +}; |
0 commit comments