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

thoughtspot / visual-embed-sdk / #1451

16 Jan 2025 06:06AM UTC coverage: 41.695% (-52.2%) from 93.86%
#1451

Pull #65

Prashant.patil
SCAL-233454-exp removing all extra config and checking
Pull Request #65: test-exported memb

273 of 1114 branches covered (24.51%)

Branch coverage included in aggregate %.

84 of 366 new or added lines in 14 files covered. (22.95%)

1011 existing lines in 23 files now uncovered.

1301 of 2661 relevant lines covered (48.89%)

9.09 hits per line

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

18.42
/src/utils/authService/authService.ts
1
import { logger } from '../logger';
24✔
2

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

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

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

UNCOV
53
    return false;
×
54
}
55

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

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

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

114
/**
115
 *
116
 * @param thoughtSpotHost
117
 * @param username
118
 * @param password
119
 */
120
export async function fetchBasicAuthService(
24✔
121
    thoughtSpotHost: string,
122
    username: string,
123
    password: string,
124
): Promise<any> {
UNCOV
125
    return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.BASIC_LOGIN}`, {
×
126
        method: 'POST',
127
        headers: {
128
            'content-type': 'application/x-www-form-urlencoded',
129
            'x-requested-by': 'ThoughtSpot',
130
        },
131
        body: `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}`,
132
        credentials: 'include',
133
    });
134
}
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

© 2026 Coveralls, Inc