Skip to content

Commit

Permalink
need to upgrade user store to store access token
Browse files Browse the repository at this point in the history
  • Loading branch information
amrita-shrestha committed Oct 18, 2024
1 parent eb23a98 commit c4473ae
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 4 deletions.
6 changes: 6 additions & 0 deletions tests/e2e/cucumber/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,19 @@ Before(async function (this: World, { pickle }: ITestCaseHookParameter) {
break
}
})
const tags = pickle.tags.map(tag => tag.name);

if (!config.basicAuth) {
const user = this.usersEnvironment.getUser({ key: 'admin' })
if (config.keycloak) {
await setAccessTokenForKeycloakOcisUser(user)
await setAccessTokenForKeycloakUser(user)
} else {
await setAdminToken(user)
if (tags.includes('@ocm')){
config.federatedServer = true
await setAdminToken(user)
}
}
}
})
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/cucumber/features/ocm/ocm.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@ocm
Feature: federation management

Scenario: user create federated share
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/support/api/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getAuthHeader = (user: User, isKeycloakRequest: boolean = false) =>
const authHeader = {
Authorization: 'Basic ' + Buffer.from(user.id + ':' + user.password).toString('base64')
}

console.log(authHeader)
if (!config.basicAuth) {
authHeader.Authorization = 'Bearer ' + tokenEnvironment.getToken({ user }).accessToken
}
Expand All @@ -32,7 +32,7 @@ export const request = async ({
isKeycloakRequest?: boolean
}): Promise<Response> => {
const authHeader = getAuthHeader(user, isKeycloakRequest)

console.log(authHeader)
const basicHeader = {
'OCS-APIREQUEST': true as any,
...(user.id && authHeader),
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/support/api/token/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Token {
}

const getAuthorizedEndPoint = async (user: User): Promise<Array<string>> => {
console.log(config.baseUrl)
const logonResponse = await fetch(config.baseUrl + '/signin/v1/identifier/_/logon', {
method: 'POST',
headers: {
Expand Down Expand Up @@ -101,6 +102,7 @@ export const setAccessAndRefreshToken = async (user: User) => {
const tokenList = (await response.json()) as Token

const tokenEnvironment = TokenEnvironmentFactory()
console.log(tokenEnvironment)
tokenEnvironment.setToken({
user: { ...user },
token: {
Expand Down
33 changes: 32 additions & 1 deletion tests/e2e/support/environment/userManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
dummyGroupStore,
createdUserStore,
createdGroupStore,
keycloakCreatedUser
keycloakCreatedUser, newUserStore
} from '../store'

export class UsersEnvironment {
Expand Down Expand Up @@ -124,4 +124,35 @@ export class UsersEnvironment {

return keycloakCreatedUser.delete(userKey)
}
storeNewCreatedUser({ user }: { user: User }, instanceName: string): User {
// Check if the outer Map has an entry for the instance
if (!newUserStore.has(instanceName)) {
// If not, create a new inner Map for this instance
newUserStore.set(instanceName, new Map<string, User>())
}

const instanceUsers = newUserStore.get(instanceName)
// Check if the user already exists in the inner Map
if (instanceUsers && instanceUsers.has(user.id)) {
throw new Error(`User '${user.id}' already exists in '${instanceName}'`)
}

// Store the new user in the inner Map for the current instance
instanceUsers?.set(user.id, user) // Use user.id as the key

return user // Return the user object
}
getNewCreatedUser({ instanceName, userId }: { instanceName: string; userId: string }): User {
const userKey = userId.toLowerCase() // Normalize user ID (if needed)
if (!newUserStore.has(instanceName)) {
throw new Error(`Instance '${instanceName}' not found`)
}

const instanceUsers = newUserStore.get(instanceName)
if (!instanceUsers || !instanceUsers.has(userKey)) {
throw new Error(`User '${userKey}' not found in '${instanceName}'`)
}

return instanceUsers.get(userKey)! // Return the user, using non-null assertion
}
}
2 changes: 1 addition & 1 deletion tests/e2e/support/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { actorStore } from './actor'
export { createdLinkStore, roleDisplayText, securePassword } from './link'
export { createdSpaceStore } from './space'
export { dummyUserStore, createdUserStore } from './user'
export { dummyUserStore, createdUserStore, newUserStore } from './user'
export { dummyGroupStore, createdGroupStore } from './group'
export { userRoleStore } from './role'
export { keycloakRealmRoles, keycloakCreatedUser } from './keycloak'
2 changes: 2 additions & 0 deletions tests/e2e/support/store/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { User } from '../types'

export const newUserStore = new Map<string, Map<string, User>>();

export const dummyUserStore = new Map<string, User>([
[
'admin',
Expand Down

0 comments on commit c4473ae

Please sign in to comment.