• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thoughtspot / visual-embed-sdk / #1337

03 Jan 2025 06:00AM UTC coverage: 90.769% (-2.9%) from 93.701%
#1337

Pull #65

yinstardev
SCAL-233454-exp temp-testcases skip
Pull Request #65: test-exported memb

918 of 1087 branches covered (84.45%)

Branch coverage included in aggregate %.

76 of 135 new or added lines in 7 files covered. (56.3%)

19 existing lines in 2 files now uncovered.

2376 of 2542 relevant lines covered (93.47%)

52.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

41.03
/src/utils/authService/authService.ts
1
import fetch from 'cross-fetch';
26✔
2
import { logger } from '../logger';
26✔
3

4
export const EndPoints = {
26✔
5
    AUTH_VERIFICATION: '/callosum/v1/session/info',
6
    SESSION_INFO: '/callosum/v1/session/info',
7
    SAML_LOGIN_TEMPLATE: (targetUrl: string) => `/callosum/v1/saml/login?targetURLPath=${targetUrl}`,
6✔
8
    OIDC_LOGIN_TEMPLATE: (targetUrl: string) => `/callosum/v1/oidc/login?targetURLPath=${targetUrl}`,
2✔
9
    TOKEN_LOGIN: '/callosum/v1/session/login/token',
10
    BASIC_LOGIN: '/callosum/v1/session/login',
11
    LOGOUT: '/callosum/v1/session/logout',
12
    EXECUTE_TML: '/api/rest/2.0/metadata/tml/import',
13
    EXPORT_TML: '/api/rest/2.0/metadata/tml/export',
14
    IS_ACTIVE: '/callosum/v1/session/isactive',
15
};
16

17
/**
18
 *
19
 * @param url
20
 * @param options
21
 */
22
function failureLoggedFetch(url: string, options: RequestInit = {}): Promise<Response> {
×
23
    return fetch(url, options).then(async (r) => {
4✔
24
        if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
3!
UNCOV
25
            logger.error('Failure', await r.text?.());
×
26
        }
UNCOV
27
        return r;
×
28
    });
29
}
30

31
/**
32
 * Service to validate a auth token against a ThoughtSpot host.
33
 * @param thoughtSpotHost : ThoughtSpot host to verify the token against.
34
 * @param authToken : Auth token to verify.
35
 */
36
export async function verifyTokenService(
26✔
37
    thoughtSpotHost: string,
38
    authToken: string,
39
): Promise<boolean> {
UNCOV
40
    const authVerificationUrl = `${thoughtSpotHost}${EndPoints.IS_ACTIVE}`;
×
UNCOV
41
    try {
×
UNCOV
42
        const res = await fetch(authVerificationUrl, {
×
43
            headers: {
44
                Authorization: `Bearer ${authToken}`,
45
                'x-requested-by': 'ThoughtSpot',
46
            },
47
            credentials: 'omit',
48
        });
UNCOV
49
        return res.ok;
×
50
    } catch (e) {
UNCOV
51
        logger.warn(`Token Verification Service failed : ${e.message}`);
×
52
    }
53

UNCOV
54
    return false;
×
55
}
56

57
/**
58
 *
59
 * @param authEndpoint
60
 */
61
export async function fetchAuthTokenService(authEndpoint: string): Promise<any> {
26✔
UNCOV
62
    return fetch(authEndpoint);
×
63
}
64

65
/**
66
 *
67
 * @param thoughtSpotHost
68
 * @param username
69
 * @param authToken
70
 */
71
export async function fetchAuthService(
26✔
72
    thoughtSpotHost: string,
73
    username: string,
74
    authToken: string,
75
): Promise<any> {
UNCOV
76
    const fetchUrlParams = username
×
77
        ? `username=${username}&auth_token=${authToken}`
78
        : `auth_token=${authToken}`;
UNCOV
79
    return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.TOKEN_LOGIN}?${fetchUrlParams}`, {
×
80
        credentials: 'include',
81
        // We do not want to follow the redirect, as it starts giving a CORS
82
        // error
83
        redirect: 'manual',
84
    });
85
}
86

87
/**
88
 *
89
 * @param thoughtSpotHost
90
 * @param username
91
 * @param authToken
92
 */
93
export async function fetchAuthPostService(
26✔
94
    thoughtSpotHost: string,
95
    username: string,
96
    authToken: string,
97
): Promise<any> {
98
    const bodyPrams = username
4!
99
        ? `username=${encodeURIComponent(username)}&auth_token=${encodeURIComponent(authToken)}`
100
        : `auth_token=${encodeURIComponent(authToken)}`;
101
    return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.TOKEN_LOGIN}`, {
4✔
102
        method: 'POST',
103
        headers: {
104
            'content-type': 'application/x-www-form-urlencoded',
105
            'x-requested-by': 'ThoughtSpot',
106
        },
107
        body: bodyPrams,
108
        credentials: 'include',
109
        // We do not want to follow the redirect, as it starts giving a CORS
110
        // error
111
        redirect: 'manual',
112
    });
113
}
114

115
/**
116
 *
117
 * @param thoughtSpotHost
118
 * @param username
119
 * @param password
120
 */
121
export async function fetchBasicAuthService(
26✔
122
    thoughtSpotHost: string,
123
    username: string,
124
    password: string,
125
): Promise<any> {
UNCOV
126
    return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.BASIC_LOGIN}`, {
×
127
        method: 'POST',
128
        headers: {
129
            'content-type': 'application/x-www-form-urlencoded',
130
            'x-requested-by': 'ThoughtSpot',
131
        },
132
        body: `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}`,
133
        credentials: 'include',
134
    });
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc