Skip to content

Commit

Permalink
Use configured hostname for access token
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkisemils authored and buggmagnet committed Jun 10, 2024
1 parent 33cdec4 commit e47061f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
7 changes: 7 additions & 0 deletions ios/MullvadVPNUITests/AccountTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

import XCTest

class AccountApi: XCTestCase {
func testApi() throws {
let temporaryAccountNumber = try MullvadAPIWrapper().createAccount()
try MullvadAPIWrapper().addDevices(5, account: temporaryAccountNumber)
}
}

class AccountTests: LoggedOutUITestCase {
override func setUpWithError() throws {
continueAfterFailure = false
Expand Down
4 changes: 1 addition & 3 deletions mullvad-api/src/abortable_stream.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Wrapper around a stream to make it abortable. This allows in-flight requests to be cancelled
//! immediately instead of after the socket times out.
use futures::channel::oneshot;
use futures::future::Fuse;
use futures::FutureExt;
use futures::{channel::oneshot, future::Fuse, FutureExt};
use hyper::client::connect::{Connected, Connection};
use std::{
future::Future,
Expand Down
10 changes: 6 additions & 4 deletions mullvad-api/src/access.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use crate::{
rest,
rest::{RequestFactory, RequestServiceHandle},
API,
};
use futures::{
channel::{mpsc, oneshot},
StreamExt,
};
use hyper::StatusCode;
use mullvad_types::account::{AccessToken, AccessTokenData, AccountToken};
use std::collections::HashMap;
use std::{borrow::Cow, collections::HashMap};
use tokio::select;

pub const AUTH_URL_PREFIX: &str = "auth/v1";
Expand Down Expand Up @@ -37,8 +36,11 @@ struct AccountState {
}

impl AccessTokenStore {
pub(crate) fn new(service: RequestServiceHandle) -> Self {
let factory = rest::RequestFactory::new(API.host(), None);
pub(crate) fn new(
service: RequestServiceHandle,
hostname: impl Into<Cow<'static, str>>,
) -> Self {
let factory = rest::RequestFactory::new(hostname, None);
let (tx, rx) = mpsc::unbounded();
tokio::spawn(Self::service_requests(rx, service, factory));
Self { tx }
Expand Down
2 changes: 1 addition & 1 deletion mullvad-api/src/ffi/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct MullvadApiError {

impl MullvadApiError {
pub fn new(kind: MullvadApiErrorKind, error: &dyn std::error::Error) -> Self {
let description = CString::new(format!("{error:?}")).unwrap_or_default();
let description = CString::new(format!("{error:?}: {error}")).unwrap_or_default();
Self {
description: description.into_raw(),
kind,
Expand Down
6 changes: 3 additions & 3 deletions mullvad-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ impl Runtime {
#[cfg(target_os = "android")]
self.socket_bypass_tx.clone(),
);
let token_store = access::AccessTokenStore::new(service.clone());
let factory = rest::RequestFactory::new(API.host(), Some(token_store));
let token_store = access::AccessTokenStore::new(service.clone(), API.host());
let factory = rest::RequestFactory::new(API.host().to_owned(), Some(token_store));

rest::MullvadRestHandle::new(service, factory, self.availability_handle())
}
Expand All @@ -448,7 +448,7 @@ impl Runtime {
#[cfg(target_os = "android")]
self.socket_bypass_tx.clone(),
);
let token_store = access::AccessTokenStore::new(service.clone());
let token_store = access::AccessTokenStore::new(service.clone(), hostname.clone());
let factory = rest::RequestFactory::new(hostname, Some(token_store));

rest::MullvadRestHandle::new(service, factory, self.availability_handle())
Expand Down

0 comments on commit e47061f

Please sign in to comment.