srctree

Gregory Mullen parent 015ec152 a5059493
move invalid auth provider into auth/provider.zig

inlinesplit
src/auth.zig added: 34, removed: 39, total 0
@@ -17,40 +17,6 @@ pub const Error = error{
UnknownUser,
};
 
pub const InvalidAuth = struct {
pub fn provider() Provider {
return Provider{
.ctx = undefined,
.vtable = .{
.authenticate = authenticate,
.valid = valid,
.lookup_user = lookupUser,
.create_session = createSession,
.get_cookie = getCookie,
},
};
}
 
fn authenticate(_: *const anyopaque, _: *const Headers) Error!User {
return error.UnknownUser;
}
 
fn createSession(_: *const anyopaque, _: *const User) Error!void {
return error.Unauthenticated;
}
fn getCookie(_: *const anyopaque, _: User) Error!?RequestCookie {
return error.Unauthenticated;
}
 
fn valid(_: *const anyopaque, _: *const User) bool {
return false;
}
 
fn lookupUser(_: *const anyopaque, _: []const u8) Error!User {
return error.UnknownUser;
}
};
 
const TestingAuth = struct {
pub fn init() TestingAuth {
return .{};
 
src/auth/provider.zig added: 34, removed: 39, total 0
@@ -87,8 +87,37 @@ test "Provider" {
try std.testing.expectEqual(null, p.getCookie(undefined));
}
 
pub const invalid: Provider = .{
.ctx = undefined,
.vtable = .{
.authenticate = Invalid.authenticate,
.valid = Invalid.valid,
.lookup_user = Invalid.lookupUser,
.create_session = Invalid.createSession,
.get_cookie = Invalid.getCookie,
},
};
 
pub const Invalid = struct {
fn authenticate(_: *const anyopaque, _: *const Headers) Error!User {
return error.UnknownUser;
}
fn createSession(_: *const anyopaque, _: *const User) Error!void {
return error.Unauthenticated;
}
fn getCookie(_: *const anyopaque, _: User) Error!?RequestCookie {
return error.Unauthenticated;
}
fn valid(_: *const anyopaque, _: *const User) bool {
return false;
}
fn lookupUser(_: *const anyopaque, _: []const u8) Error!User {
return error.UnknownUser;
}
};
 
const Auth = @import("../auth.zig");
pub const Error = Auth.Error;
const Error = Auth.Error;
const Headers = @import("../headers.zig");
const RequestCookie = @import("../cookies.zig").Cookie;
const User = @import("user.zig");
 
src/server.zig added: 34, removed: 39, total 0
@@ -24,7 +24,7 @@ pub const Interface = union(RunModes) {
 
pub const Options = struct {
mode: RunMode = .{ .http = .{} },
auth: Auth.Provider = Auth.InvalidAuth.provider(),
auth: Auth.Provider = .invalid,
};
 
pub fn init(a: Allocator, router: Router, opts: Options) !Server {