All files / universal/gpii/node_modules/gpii-oauth2/gpii-oauth2-authz-server/test/js AuthGrantFinderTests.js

100% Statements 9/9
100% Branches 0/0
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169                                  2x   2x   2x                 2x                 2x                                               2x                                     2x                                                                 2x             2x                                                                                            
/*!
Copyright 2016-2017 OCAD university
 
Licensed under the New BSD license. You may not use this file except in
compliance with this License.
 
The research leading to these results has received funding from the European Union's
Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016.
 
You may obtain a copy of the License at
https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
 
/* global fluid */
 
"use strict";
 
(function () {
 
    var gpii = fluid.registerNamespace("gpii");
 
    fluid.defaults("gpii.tests.oauth2.authorizationService", {
        gradeNames: ["gpii.oauth2.authorizationService"],
        components: {
            codeGenerator: {
                type: "fluid.emptySubcomponent"
            }
        }
    });
 
    fluid.defaults("gpii.tests.oauth2.authGrantFinder", {
        gradeNames: ["gpii.oauth2.authGrantFinder"],
        components: {
            authorizationService: {
                type: "gpii.tests.oauth2.authorizationService"
            }
        }
    });
 
    fluid.defaults("gpii.tests.oauth2.authGrantFinder.testEnvironment", {
        gradeNames: ["gpii.tests.oauth2.pouchBackedTestEnvironment"],
        dbViewsLocation: "../../../gpii-oauth2-datastore/dbViews/views.json",
        dbName: "auth",
        components: {
            authGrantFinder: {
                type: "gpii.tests.oauth2.authGrantFinder",
                createOnEvent: "onFixturesConstructed",
                options: {
                    gradeNames: ["gpii.tests.oauth2.dbDataStore.base"],
                    dbViews: "{arguments}.0"
                }
            },
            caseHolder: {
                type: "gpii.tests.inBrowserPouchDB.baseTestCaseHolder"
            }
        },
        distributeOptions: [{
            record: "gpii.oauth2.dbDataStore",
            target: "{that dataStore}.type"
        }]
    });
 
    // Tests with an empty data store
    fluid.defaults("gpii.tests.oauth2.authGrantFinder.emptyDataStore", {
        gradeNames: ["gpii.tests.oauth2.authGrantFinder.testEnvironment"],
        rawModules: [{
            name: "Test getGrantForAccessToken()",
            tests: [{
                name: "getGrantForAccessToken() should return undefined with an empty dataStore",
                sequence: [{
                    func: "gpii.tests.oauth2.invokePromiseProducer",
                    args: ["{authGrantFinder}.getGrantForAccessToken", ["any-token"], "{that}"]
                }, {
                    listener: "jqUnit.assertUndefined",
                    args: ["undefined should be received", "{arguments}.0"],
                    event: "{that}.events.onResponse"
                }]
            }]
        }]
    });
 
    // Tests with a data store having test data
    gpii.tests.oauth2.authGrantFinder.testData = [{
        "_id": "gpiiToken-1",
        "type": "gpiiToken",
        "gpiiToken": "carol_gpii_token"
    }, {
        "_id": "client-1",
        "type": "gpiiAppInstallationClient",
        "name": "Bakersfield AJC - PC1",
        "oauth2ClientId": "Bakersfield-AJC-client-id",
        "oauth2ClientSecret": "Bakersfield-AJC-client-secret"
    }, {
        "_id": "gpiiAppInstallationAuthorization-1",
        "type": "gpiiAppInstallationAuthorization",
        "clientId": "client-1",
        "gpiiToken": "carol_gpii_token",
        "accessToken": "Bakersfiled_AJC_access_token",
        "revoked": false,
        "timestampCreated": new Date(new Date().getTime() - 60 * 1000).toISOString(),
        "timestampRevoked": null,
        "timestampExpires": new Date(new Date().getTime() + 40 * 1000).toISOString()
    }, {
        "_id": "gpiiAppInstallationAuthorization-expired",
        "type": "gpiiAppInstallationAuthorization",
        "clientId": "client-1",
        "gpiiToken": "carol_gpii_token",
        "accessToken": "Bakersfiled_AJC_access_token_expired",
        "revoked": false,
        "timestampCreated": new Date(new Date().getTime() - 60 * 1000).toISOString(),
        "timestampRevoked": null,
        "timestampExpires": new Date(new Date().getTime() - 20 * 1000).toISOString()
    }];
 
    // All expected results
    gpii.tests.oauth2.authGrantFinder.expected = {
        accessToken: "Bakersfiled_AJC_access_token",
        gpiiToken: "carol_gpii_token",
        allowUntrustedSettingsGet: true,
        allowUntrustedSettingsPut: true
    };
 
    fluid.defaults("gpii.tests.oauth2.authGrantFinder.withData", {
        gradeNames: ["gpii.tests.oauth2.authGrantFinder.testEnvironment"],
        pouchData: gpii.tests.oauth2.authGrantFinder.testData,
        rawModules: [{
            name: "Test getGrantForAccessToken()",
            tests: [{
                name: "getGrantForAccessToken() returns undefined for an unknown access token",
                sequence: [{
                    func: "gpii.tests.oauth2.invokePromiseProducer",
                    args: ["{authGrantFinder}.getGrantForAccessToken", ["unknown"], "{that}"]
                }, {
                    listener: "jqUnit.assertUndefined",
                    args: ["undefined should be received for an unknown access token", "{arguments}.0"],
                    event: "{that}.events.onResponse"
                }]
            }]
        }, {
            name: "Test getGrantForAccessToken() with an access token for resource owner GPII token grant type",
            tests: [{
                name: "getGrantForAccessToken() returns the authorization info in the format for the resource owner GPII token grant type",
                sequence: [{
                    func: "gpii.tests.oauth2.invokePromiseProducer",
                    args: ["{authGrantFinder}.getGrantForAccessToken", ["Bakersfiled_AJC_access_token"], "{that}"]
                }, {
                    listener: "jqUnit.assertDeepEq",
                    args: ["The expected authorization info is returned", gpii.tests.oauth2.authGrantFinder.expected, "{arguments}.0"],
                    event: "{that}.events.onResponse"
                }]
            }]
        }, {
            name: "Test getGrantForAccessToken() returns undefined for an expired access token",
            tests: [{
                name: "getGrantForAccessToken() returns undefined for an expired access token",
                sequence: [{
                    func: "gpii.tests.oauth2.invokePromiseProducer",
                    args: ["{authGrantFinder}.getGrantForAccessToken", ["Bakersfiled_AJC_access_token_expired"], "{that}"]
                }, {
                    listener: "jqUnit.assertUndefined",
                    args: ["The expected authorization info is returned", "{arguments}.0"],
                    event: "{that}.events.onResponse"
                }]
            }]
        }]
    });
 
})();