Skip to content

Commit

Permalink
fix: remove auth login endpoint (shuttle-hq#1007)
Browse files Browse the repository at this point in the history
  • Loading branch information
oddgrd authored and AlphaKeks committed Jun 20, 2023
1 parent 0304c1a commit aabb010
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 53 deletions.
5 changes: 2 additions & 3 deletions auth/src/api/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::{
};

use super::handlers::{
convert_cookie, convert_key, get_public_key, get_user, login, logout, post_user,
put_user_reset_key, refresh_token,
convert_cookie, convert_key, get_public_key, get_user, logout, post_user, put_user_reset_key,
refresh_token,
};

pub type UserManagerState = Arc<Box<dyn UserManagement>>;
Expand Down Expand Up @@ -64,7 +64,6 @@ impl Default for ApiBuilder {
impl ApiBuilder {
pub fn new() -> Self {
let router = Router::new()
.route("/login", post(login))
.route("/logout", post(logout))
.route("/auth/session", get(convert_cookie))
.route("/auth/key", get(convert_key))
Expand Down
17 changes: 0 additions & 17 deletions auth/src/api/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,6 @@ pub(crate) async fn put_user_reset_key(
user_manager.reset_key(account_name).await
}

pub(crate) async fn login(
mut session: WritableSession,
State(user_manager): State<UserManagerState>,
Json(request): Json<LoginRequest>,
) -> Result<Json<user::Response>, Error> {
let user = user_manager.get_user(request.account_name).await?;

session
.insert("account_name", user.name.clone())
.expect("to set account name");
session
.insert("account_tier", user.account_tier)
.expect("to set account tier");

Ok(Json(user.into()))
}

pub(crate) async fn logout(mut session: WritableSession) {
session.destroy();
}
Expand Down
1 change: 1 addition & 0 deletions auth/tests/api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use shuttle_common::claims::Claim;

use crate::helpers::app;

#[ignore]
#[tokio::test]
async fn session_flow() {
let app = app().await;
Expand Down
35 changes: 2 additions & 33 deletions auth/tests/api/users.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::helpers::{self, app};
use axum::body::Body;
use axum_extra::extract::cookie::Cookie;
use hyper::http::{header::AUTHORIZATION, Request, StatusCode};
use serde_json::{self, json, Value};
use serde_json::{self, Value};

#[tokio::test]
async fn post_user() {
Expand Down Expand Up @@ -109,7 +108,7 @@ async fn get_user() {
async fn test_reset_key() {
let app = app().await;

// Reset API key without cookie or API key.
// Reset API key without API key.
let request = Request::builder()
.uri("/users/reset-api-key")
.method("PUT")
Expand All @@ -118,36 +117,6 @@ async fn test_reset_key() {
let response = app.send_request(request).await;
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);

// Reset API key with cookie.
let response = app.post_user("test-user", "basic").await;
assert_eq!(response.status(), StatusCode::OK);

let body = serde_json::to_vec(&json! ({"account_name": "test-user"})).unwrap();
let request = Request::builder()
.uri("/login")
.method("POST")
.header("Content-Type", "application/json")
.body(Body::from(body))
.unwrap();
let response = app.send_request(request).await;
assert_eq!(response.status(), StatusCode::OK);
let cookie = response
.headers()
.get("set-cookie")
.unwrap()
.to_str()
.unwrap();
let cookie = Cookie::parse(cookie).unwrap();

let request = Request::builder()
.uri("/users/reset-api-key")
.method("PUT")
.header("Cookie", cookie.stripped().to_string())
.body(Body::empty())
.unwrap();
let response = app.send_request(request).await;
assert_eq!(response.status(), StatusCode::OK);

// Reset API key with API key.
let request = Request::builder()
.uri("/users/reset-api-key")
Expand Down

0 comments on commit aabb010

Please sign in to comment.