Skip to content

Commit

Permalink
feat: 🎸 Remove required personal number in route (#118)
Browse files Browse the repository at this point in the history
When using bankId app on the same device the personal number is not
required
  • Loading branch information
whyer authored Apr 17, 2021
1 parent 9c4fcb2 commit c3b4b15
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
8 changes: 6 additions & 2 deletions lib/__tests__/__snapshots__/routes.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ exports[`handles route children 1`] = `"https://etjanst.stockholm.se/vardnadshav

exports[`handles route classmates 1`] = `"https://etjanst.stockholm.se/vardnadshavare/inloggad2/contacts/GetStudentsByClass?studentId=123"`;

exports[`handles route classmates 2`] = `"https://etjanst.stockholm.se/vardnadshavare/base/getuserdata"`;

exports[`handles route image 1`] = `"https://etjanst.stockholm.se/vardnadshavare/inloggad2/NewsBanner?url=https://example.com/img.png"`;

exports[`handles route login with personal number 1`] = `"https://login003.stockholm.se/NECSadcmbid/authenticate/NECSadcmbid?TARGET=-SM-HTTPS%3a%2f%2flogin001%2estockholm%2ese%2fNECSadc%2fmbid%2fb64startpage%2ejsp%3fstartpage%3daHR0cHM6Ly9ldGphbnN0LnN0b2NraG9sbS5zZS92YXJkbmFkc2hhdmFyZS9pbmxvZ2dhZDIvaGVt&initialize=bankid&personalNumber=201701012393&_=1618404258782"`;

exports[`handles route login without personal number 1`] = `"https://login003.stockholm.se/NECSadcmbid/authenticate/NECSadcmbid?TARGET=-SM-HTTPS%3a%2f%2flogin001%2estockholm%2ese%2fNECSadc%2fmbid%2fb64startpage%2ejsp%3fstartpage%3daHR0cHM6Ly9ldGphbnN0LnN0b2NraG9sbS5zZS92YXJkbmFkc2hhdmFyZS9pbmxvZ2dhZDIvaGVt&initialize=bankid&_=1618404258782"`;

exports[`handles route menuChoice 1`] = `"https://etjanst.stockholm.se/vardnadshavare/inloggad2/Matsedel/GetMatsedelChoice?childId=123"`;

exports[`handles route menuList 1`] = `"https://etjanst.stockholm.se/vardnadshavare/inloggad2/Matsedel/GetMatsedelList?childId=123"`;
Expand All @@ -23,3 +25,5 @@ exports[`handles route newsDetails 1`] = `"https://etjanst.stockholm.se/vardnads
exports[`handles route notifications 1`] = `"https://etjanst.stockholm.se/vardnadshavare/inloggad2/Overview/GetNotification?childId=123"`;

exports[`handles route schedule 1`] = `"https://etjanst.stockholm.se/vardnadshavare/inloggad2/Calender/GetSchema?childId=123&startDate=2021-01-01&endDate=2021-01-01"`;

exports[`handles route user 1`] = `"https://etjanst.stockholm.se/vardnadshavare/base/getuserdata"`;
6 changes: 5 additions & 1 deletion lib/__tests__/routes.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as routes from '../routes'

Date.now = jest.fn(() => 1618404258782)

test.each([
['children', routes.children],
['calender', routes.calendar('123')],
['classmates', routes.classmates('123')],
['classmates', routes.user],
['user', routes.user],
['news', routes.news('123')],
['newsDetails', routes.newsDetails('123', '321')],
['image', routes.image('https://example.com/img.png')],
Expand All @@ -13,6 +15,8 @@ test.each([
['menuList', routes.menuList('123')],
['menuChoice', routes.menuChoice('123')],
['schedule', routes.schedule('123', '2021-01-01', '2021-01-01')],
['login with personal number', routes.login('201701012393')],
['login without personal number', routes.login()],
])('handles route %s', (_name, input) => {
expect(input).toMatchSnapshot()
})
4 changes: 2 additions & 2 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export class Api extends EventEmitter {
this.headers[name] = value
}

public async login(personalNumber: string): Promise<LoginStatusChecker> {
if (personalNumber.endsWith('1212121212')) return this.fakeMode()
public async login(personalNumber?: string): Promise<LoginStatusChecker> {
if (personalNumber !== undefined && personalNumber.endsWith('1212121212')) return this.fakeMode()

this.isFake = false

Expand Down
9 changes: 6 additions & 3 deletions lib/routes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export const login = (personalNumber: string) =>
`https://login003.stockholm.se/NECSadcmbid/authenticate/NECSadcmbid?TARGET=-SM-HTTPS%3a%2f%2flogin001%2estockholm%2ese%2fNECSadc%2fmbid%2fb64startpage%2ejsp%3fstartpage%3daHR0cHM6Ly9ldGphbnN0LnN0b2NraG9sbS5zZS92YXJkbmFkc2hhdmFyZS9pbmxvZ2dhZDIvaGVt&initialize=bankid&personalNumber=${personalNumber}&_=${Date.now()}`
export const login = (personalNumber?: string) => {
const baseUrl = 'https://login003.stockholm.se/NECSadcmbid/authenticate/NECSadcmbid?TARGET=-SM-HTTPS%3a%2f%2flogin001%2estockholm%2ese%2fNECSadc%2fmbid%2fb64startpage%2ejsp%3fstartpage%3daHR0cHM6Ly9ldGphbnN0LnN0b2NraG9sbS5zZS92YXJkbmFkc2hhdmFyZS9pbmxvZ2dhZDIvaGVt'
const optionalPersonalNumber = personalNumber === undefined ? '' : `&personalNumber=${personalNumber}`
return `${baseUrl}&initialize=bankid${optionalPersonalNumber}&_=${Date.now()}`
}

export const loginStatus = (order: string) =>
export const loginStatus = (order: string) =>
`https://login003.stockholm.se/NECSadcmbid/authenticate/NECSadcmbid?TARGET=-SM-HTTPS%3a%2f%2flogin001%2estockholm%2ese%2fNECSadc%2fmbid%2fb64startpage%2ejsp%3fstartpage%3daHR0cHM6Ly9ldGphbnN0LnN0b2NraG9sbS5zZS92YXJkbmFkc2hhdmFyZS9pbmxvZ2dhZDIvaGVt&verifyorder=${order}&_=${Date.now()}`

export const loginCookie =
Expand Down

0 comments on commit c3b4b15

Please sign in to comment.