Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
package main
2017-10-16 07:32:58 +00:00
import (
2017-10-21 00:27:47 +00:00
"bytes"
2017-10-16 07:32:58 +00:00
"fmt"
2017-10-21 00:27:47 +00:00
"net/http/httptest"
2017-10-16 07:32:58 +00:00
"runtime/debug"
"strconv"
"testing"
"time"
)
2017-10-21 00:27:47 +00:00
func recordMustExist ( t * testing . T , err error , errmsg string , args ... interface { } ) {
2017-10-16 07:32:58 +00:00
if err == ErrNoRows {
2017-10-21 00:27:47 +00:00
t . Errorf ( errmsg , args ... )
2017-10-16 07:32:58 +00:00
} else if err != nil {
t . Fatal ( err )
}
}
2017-10-21 00:27:47 +00:00
func recordMustNotExist ( t * testing . T , err error , errmsg string , args ... interface { } ) {
2017-10-16 07:32:58 +00:00
if err == nil {
2017-10-21 00:27:47 +00:00
t . Errorf ( errmsg , args ... )
2017-10-16 07:32:58 +00:00
} else if err != ErrNoRows {
t . Fatal ( err )
}
}
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
func TestUserStore ( t * testing . T ) {
2017-09-03 04:50:31 +00:00
if ! gloinited {
err := gloinit ( )
if err != nil {
t . Fatal ( err )
}
}
if ! pluginsInited {
initPlugins ( )
}
2017-11-02 13:35:19 +00:00
var err error
users , err = NewMemoryUserStore ( config . UserCacheCapacity )
expectNilErr ( t , err )
2017-09-18 17:03:52 +00:00
users . ( UserCache ) . Flush ( )
2017-10-16 07:32:58 +00:00
userStoreTest ( t , 2 )
2017-11-02 13:35:19 +00:00
users , err = NewSQLUserStore ( )
expectNilErr ( t , err )
2017-10-16 07:32:58 +00:00
userStoreTest ( t , 3 )
2017-09-15 22:20:01 +00:00
}
2017-10-16 07:32:58 +00:00
func userStoreTest ( t * testing . T , newUserID int ) {
2017-09-18 17:03:52 +00:00
ucache , hasCache := users . ( UserCache )
2017-10-21 00:27:47 +00:00
// Go doesn't have short-circuiting, so this'll allow us to do one liner tests
if ! hasCache {
ucache = & NullUserStore { }
2017-09-18 17:03:52 +00:00
}
2017-10-21 00:27:47 +00:00
expect ( t , ( ! hasCache || ucache . Length ( ) == 0 ) , fmt . Sprintf ( "The initial ucache length should be zero, not %d" , ucache . Length ( ) ) )
2017-09-03 04:50:31 +00:00
2017-10-21 00:27:47 +00:00
_ , err := users . Get ( - 1 )
2017-10-16 07:32:58 +00:00
recordMustNotExist ( t , err , "UID #-1 shouldn't exist" )
2017-10-21 00:27:47 +00:00
expect ( t , ! hasCache || ucache . Length ( ) == 0 , fmt . Sprintf ( "We found %d items in the user cache and it's supposed to be empty" , ucache . Length ( ) ) )
2017-09-18 17:03:52 +00:00
2017-09-15 22:20:01 +00:00
_ , err = users . Get ( 0 )
2017-10-16 07:32:58 +00:00
recordMustNotExist ( t , err , "UID #0 shouldn't exist" )
2017-10-21 00:27:47 +00:00
expect ( t , ! hasCache || ucache . Length ( ) == 0 , fmt . Sprintf ( "We found %d items in the user cache and it's supposed to be empty" , ucache . Length ( ) ) )
2017-09-03 04:50:31 +00:00
2017-10-21 00:27:47 +00:00
user , err := users . Get ( 1 )
2017-10-16 07:32:58 +00:00
recordMustExist ( t , err , "Couldn't find UID #1" )
2017-09-03 04:50:31 +00:00
2017-10-21 00:27:47 +00:00
expect ( t , user . ID == 1 , fmt . Sprintf ( "user.ID should be 1. Got '%d' instead." , user . ID ) )
expect ( t , user . Name == "Admin" , fmt . Sprintf ( "user.Name should be 'Admin', not '%s'" , user . Name ) )
expect ( t , user . Group == 1 , "Admin should be in group 1" )
expect ( t , user . IsSuperAdmin , "Admin should be a super admin" )
expect ( t , user . IsAdmin , "Admin should be an admin" )
expect ( t , user . IsSuperMod , "Admin should be a super mod" )
expect ( t , user . IsMod , "Admin should be a mod" )
expect ( t , ! user . IsBanned , "Admin should not be banned" )
2017-10-16 07:32:58 +00:00
2017-10-21 00:27:47 +00:00
_ , err = users . Get ( newUserID )
2017-10-16 07:32:58 +00:00
recordMustNotExist ( t , err , fmt . Sprintf ( "UID #%d shouldn't exist" , newUserID ) )
2017-09-03 04:50:31 +00:00
2017-09-18 17:03:52 +00:00
if hasCache {
2017-10-16 07:32:58 +00:00
expectIntToBeX ( t , ucache . Length ( ) , 1 , "User cache length should be 1, not %d" )
2017-09-18 17:03:52 +00:00
2017-10-21 00:27:47 +00:00
_ , err = ucache . CacheGet ( - 1 )
2017-10-16 07:32:58 +00:00
recordMustNotExist ( t , err , "UID #-1 shouldn't exist, even in the cache" )
2017-10-21 00:27:47 +00:00
_ , err = ucache . CacheGet ( 0 )
2017-10-16 07:32:58 +00:00
recordMustNotExist ( t , err , "UID #0 shouldn't exist, even in the cache" )
2017-09-18 17:03:52 +00:00
user , err = ucache . CacheGet ( 1 )
2017-10-16 07:32:58 +00:00
recordMustExist ( t , err , "Couldn't find UID #1 in the cache" )
2017-09-18 17:03:52 +00:00
if user . ID != 1 {
t . Error ( "user.ID does not match the requested UID. Got '" + strconv . Itoa ( user . ID ) + "' instead." )
}
2017-10-16 07:32:58 +00:00
if user . Name != "Admin" {
t . Error ( "user.Name should be 'Admin', not '" + user . Name + "'" )
}
2017-10-21 00:27:47 +00:00
_ , err = ucache . CacheGet ( newUserID )
recordMustNotExist ( t , err , "UID #%d shouldn't exist, even in the cache" , newUserID )
2017-09-18 17:03:52 +00:00
ucache . Flush ( )
2017-10-16 07:32:58 +00:00
expectIntToBeX ( t , ucache . Length ( ) , 0 , "User cache length should be 0, not %d" )
2017-09-18 17:03:52 +00:00
}
2017-09-10 16:57:22 +00:00
// TODO: Lock onto the specific error type. Is this even possible without sacrificing the detailed information in the error message?
2017-09-03 04:50:31 +00:00
var userList map [ int ] * User
2017-09-15 22:20:01 +00:00
userList , _ = users . BulkGetMap ( [ ] int { - 1 } )
if len ( userList ) > 0 {
t . Error ( "There shouldn't be any results for UID #-1" )
}
2017-09-18 17:03:52 +00:00
if hasCache {
2017-10-16 07:32:58 +00:00
expectIntToBeX ( t , ucache . Length ( ) , 0 , "User cache length should be 0, not %d" )
2017-09-18 17:03:52 +00:00
}
2017-09-15 22:20:01 +00:00
userList , _ = users . BulkGetMap ( [ ] int { 0 } )
if len ( userList ) > 0 {
t . Error ( "There shouldn't be any results for UID #0" )
}
2017-09-18 17:03:52 +00:00
if hasCache {
2017-10-16 07:32:58 +00:00
expectIntToBeX ( t , ucache . Length ( ) , 0 , "User cache length should be 0, not %d" )
2017-09-18 17:03:52 +00:00
}
2017-09-15 22:20:01 +00:00
userList , _ = users . BulkGetMap ( [ ] int { 1 } )
if len ( userList ) == 0 {
t . Error ( "The returned map is empty for UID #1" )
} else if len ( userList ) > 1 {
t . Error ( "Too many results were returned for UID #1" )
}
user , ok := userList [ 1 ]
if ! ok {
t . Error ( "We couldn't find UID #1 in the returned map" )
t . Error ( "userList" , userList )
}
if user . ID != 1 {
t . Error ( "user.ID does not match the requested UID. Got '" + strconv . Itoa ( user . ID ) + "' instead." )
}
2017-09-18 17:03:52 +00:00
if hasCache {
2017-10-16 07:32:58 +00:00
expectIntToBeX ( t , ucache . Length ( ) , 1 , "User cache length should be 1, not %d" )
2017-09-18 17:03:52 +00:00
user , err = ucache . CacheGet ( 1 )
2017-10-16 07:32:58 +00:00
recordMustExist ( t , err , "Couldn't find UID #1 in the cache" )
2017-09-18 17:03:52 +00:00
if user . ID != 1 {
2017-10-21 00:27:47 +00:00
t . Errorf ( "user.ID does not match the requested UID. Got '%d' instead." , user . ID )
2017-09-18 17:03:52 +00:00
}
ucache . Flush ( )
}
2017-10-16 07:32:58 +00:00
expect ( t , ! users . Exists ( - 1 ) , "UID #-1 shouldn't exist" )
expect ( t , ! users . Exists ( 0 ) , "UID #0 shouldn't exist" )
expect ( t , users . Exists ( 1 ) , "UID #1 should exist" )
expect ( t , ! users . Exists ( newUserID ) , fmt . Sprintf ( "UID #%d shouldn't exist" , newUserID ) )
2017-10-21 00:27:47 +00:00
expect ( t , ! hasCache || ucache . Length ( ) == 0 , fmt . Sprintf ( "User cache length should be 0, not %d" , ucache . Length ( ) ) )
2017-10-16 07:32:58 +00:00
expectIntToBeX ( t , users . GlobalCount ( ) , 1 , "The number of users should be one, not %d" )
2017-09-03 04:50:31 +00:00
2017-10-16 07:32:58 +00:00
var awaitingActivation = 5
2017-10-21 00:27:47 +00:00
uid , err := users . Create ( "Sam" , "ReallyBadPassword" , "sam@localhost.loc" , awaitingActivation , false )
expectNilErr ( t , err )
expect ( t , uid == newUserID , fmt . Sprintf ( "The UID of the new user should be %d" , newUserID ) )
expect ( t , users . Exists ( newUserID ) , fmt . Sprintf ( "UID #%d should exist" , newUserID ) )
2017-09-03 04:50:31 +00:00
2017-10-16 07:32:58 +00:00
user , err = users . Get ( newUserID )
2017-10-21 00:27:47 +00:00
recordMustExist ( t , err , "Couldn't find UID #%d" , newUserID )
2017-10-16 07:32:58 +00:00
if user . ID != newUserID {
t . Errorf ( "The UID of the user record should be %d" , newUserID )
2017-09-15 22:20:01 +00:00
}
2017-10-21 00:27:47 +00:00
expect ( t , user . Name == "Sam" , "The user should be named Sam" )
expect ( t , ! user . IsSuperAdmin , "Sam should not be a super admin" )
expect ( t , ! user . IsAdmin , "Sam should not be an admin" )
expect ( t , ! user . IsSuperMod , "Sam should not be a super mod" )
expect ( t , ! user . IsMod , "Sam should not be a mod" )
expect ( t , ! user . IsBanned , "Sam should not be banned" )
2017-10-16 07:32:58 +00:00
expectIntToBeX ( t , user . Group , 5 , "Sam should be in group 5" )
2017-09-15 22:20:01 +00:00
2017-09-18 17:03:52 +00:00
if hasCache {
2017-10-16 07:32:58 +00:00
expectIntToBeX ( t , ucache . Length ( ) , 1 , "User cache length should be 1, not %d" )
user , err = ucache . CacheGet ( newUserID )
2017-10-21 00:27:47 +00:00
recordMustExist ( t , err , "Couldn't find UID #%d in the cache" , newUserID )
expect ( t , user . ID == newUserID , fmt . Sprintf ( "user.ID does not match the requested UID. Got '%d' instead." , user . ID ) )
2017-09-18 17:03:52 +00:00
}
2017-10-16 07:32:58 +00:00
err = user . Activate ( )
2017-10-21 00:27:47 +00:00
expectNilErr ( t , err )
2017-10-16 07:32:58 +00:00
expectIntToBeX ( t , user . Group , 5 , "Sam should still be in group 5 in this copy" )
// ? - What if we change the caching mechanism so it isn't hard purged and reloaded? We'll deal with that when we come to it, but for now, this is a sign of a cache bug
if hasCache {
expectIntToBeX ( t , ucache . Length ( ) , 0 , "User cache length should be 0, not %d" )
_ , err = ucache . CacheGet ( newUserID )
2017-10-21 00:27:47 +00:00
recordMustNotExist ( t , err , "UID #%d shouldn't be in the cache" , newUserID )
2017-10-16 07:32:58 +00:00
}
user , err = users . Get ( newUserID )
2017-10-21 00:27:47 +00:00
recordMustExist ( t , err , "Couldn't find UID #%d" , newUserID )
expect ( t , user . ID == newUserID , fmt . Sprintf ( "The UID of the user record should be %d, not %d" , newUserID , user . ID ) )
expect ( t , ! user . IsSuperAdmin , "Sam should not be a super admin" )
expect ( t , ! user . IsAdmin , "Sam should not be an admin" )
expect ( t , ! user . IsSuperMod , "Sam should not be a super mod" )
expect ( t , ! user . IsMod , "Sam should not be a mod" )
expect ( t , ! user . IsBanned , "Sam should not be banned" )
expect ( t , user . Group == config . DefaultGroup , fmt . Sprintf ( "Sam should be in group %d, not %d" , config . DefaultGroup , user . Group ) )
2017-10-16 07:32:58 +00:00
// Permanent ban
duration , _ := time . ParseDuration ( "0" )
// TODO: Attempt a double ban, double activation, and double unban
err = user . Ban ( duration , 1 )
2017-10-21 00:27:47 +00:00
expectNilErr ( t , err )
expect ( t , user . Group == config . DefaultGroup , fmt . Sprintf ( "Sam should be in group %d, not %d" , config . DefaultGroup , user . Group ) )
2017-10-16 07:32:58 +00:00
if hasCache {
expectIntToBeX ( t , ucache . Length ( ) , 0 , "User cache length should be 0, not %d" )
_ , err = ucache . CacheGet ( 2 )
2017-10-21 00:27:47 +00:00
recordMustNotExist ( t , err , "UID #%d shouldn't be in the cache" , newUserID )
2017-10-16 07:32:58 +00:00
}
user , err = users . Get ( newUserID )
2017-10-21 00:27:47 +00:00
recordMustExist ( t , err , "Couldn't find UID #%d" , newUserID )
2017-10-16 07:32:58 +00:00
if user . ID != newUserID {
t . Errorf ( "The UID of the user record should be %d" , newUserID )
}
2017-10-21 00:27:47 +00:00
expect ( t , ! user . IsSuperAdmin , "Sam should not be a super admin" )
expect ( t , ! user . IsAdmin , "Sam should not be an admin" )
expect ( t , ! user . IsSuperMod , "Sam should not be a super mod" )
expect ( t , ! user . IsMod , "Sam should not be a mod" )
expect ( t , user . IsBanned , "Sam should be banned" )
expectIntToBeX ( t , user . Group , banGroup , "Sam should be in group %d" )
2017-10-16 07:32:58 +00:00
// TODO: Do tests against the scheduled updates table and the task system to make sure the ban exists there and gets revoked when it should
err = user . Unban ( )
2017-10-21 00:27:47 +00:00
expectNilErr ( t , err )
2017-10-16 07:32:58 +00:00
expectIntToBeX ( t , user . Group , banGroup , "Sam should still be in the ban group in this copy" )
if hasCache {
expectIntToBeX ( t , ucache . Length ( ) , 0 , "User cache length should be 0, not %d" )
_ , err = ucache . CacheGet ( newUserID )
2017-10-21 00:27:47 +00:00
recordMustNotExist ( t , err , "UID #%d shouldn't be in the cache" , newUserID )
2017-10-16 07:32:58 +00:00
}
user , err = users . Get ( newUserID )
2017-10-21 00:27:47 +00:00
recordMustExist ( t , err , "Couldn't find UID #%d" , newUserID )
expectIntToBeX ( t , user . ID , newUserID , "The UID of the user record should be %d" )
expect ( t , ! user . IsSuperAdmin , "Sam should not be a super admin" )
expect ( t , ! user . IsAdmin , "Sam should not be an admin" )
expect ( t , ! user . IsSuperMod , "Sam should not be a super mod" )
expect ( t , ! user . IsMod , "Sam should not be a mod" )
expect ( t , ! user . IsBanned , "Sam should not be banned" )
expectIntToBeX ( t , user . Group , config . DefaultGroup , "Sam should be back in group %d" )
var reportsForumID = 1
var generalForumID = 2
dummyResponseRecorder := httptest . NewRecorder ( )
bytesBuffer := bytes . NewBuffer ( [ ] byte ( "" ) )
dummyRequest1 := httptest . NewRequest ( "" , "/forum/1" , bytesBuffer )
dummyRequest2 := httptest . NewRequest ( "" , "/forum/2" , bytesBuffer )
err = user . ChangeGroup ( 1 )
expectNilErr ( t , err )
expect ( t , user . Group == config . DefaultGroup , "Someone's mutated this pointer elsewhere" )
user , err = users . Get ( newUserID )
recordMustExist ( t , err , "Couldn't find UID #%d" , newUserID )
expectIntToBeX ( t , user . ID , newUserID , "The UID of the user record should be %d" )
var user2 * User = getDummyUser ( )
* user2 = * user
expect ( t , ! user . IsSuperAdmin , "Sam should not be a super admin" )
expect ( t , user . IsAdmin , "Sam should be an admin" )
expect ( t , user . IsSuperMod , "Sam should be a super mod" )
expect ( t , user . IsMod , "Sam should be a mod" )
expect ( t , ! user . IsBanned , "Sam should not be banned" )
2017-10-30 09:57:08 +00:00
_ , ferr := forumUserCheck ( dummyResponseRecorder , dummyRequest1 , user , reportsForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , user . Perms . ViewTopic , "Admins should be able to access the reports forum" )
2017-10-30 09:57:08 +00:00
_ , ferr = forumUserCheck ( dummyResponseRecorder , dummyRequest2 , user2 , generalForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , user2 . Perms . ViewTopic , "Sam should be able to access the general forum" )
err = user . ChangeGroup ( 2 )
expectNilErr ( t , err )
expect ( t , user . Group == 1 , "Someone's mutated this pointer elsewhere" )
user , err = users . Get ( newUserID )
recordMustExist ( t , err , "Couldn't find UID #%d" , newUserID )
expectIntToBeX ( t , user . ID , newUserID , "The UID of the user record should be %d" )
user2 = getDummyUser ( )
* user2 = * user
expect ( t , ! user . IsSuperAdmin , "Sam should not be a super admin" )
expect ( t , ! user . IsAdmin , "Sam should not be an admin" )
expect ( t , user . IsSuperMod , "Sam should be a super mod" )
expect ( t , user . IsMod , "Sam should be a mod" )
expect ( t , ! user . IsBanned , "Sam should not be banned" )
2017-10-30 09:57:08 +00:00
_ , ferr = forumUserCheck ( dummyResponseRecorder , dummyRequest1 , user , reportsForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , user . Perms . ViewTopic , "Mods should be able to access the reports forum" )
2017-10-30 09:57:08 +00:00
_ , ferr = forumUserCheck ( dummyResponseRecorder , dummyRequest2 , user2 , generalForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , user2 . Perms . ViewTopic , "Sam should be able to access the general forum" )
err = user . ChangeGroup ( 3 )
expectNilErr ( t , err )
expect ( t , user . Group == 2 , "Someone's mutated this pointer elsewhere" )
user , err = users . Get ( newUserID )
recordMustExist ( t , err , "Couldn't find UID #%d" , newUserID )
expectIntToBeX ( t , user . ID , newUserID , "The UID of the user record should be %d" )
user2 = getDummyUser ( )
* user2 = * user
expect ( t , ! user . IsSuperAdmin , "Sam should not be a super admin" )
expect ( t , ! user . IsAdmin , "Sam should not be an admin" )
expect ( t , ! user . IsSuperMod , "Sam should not be a super mod" )
expect ( t , ! user . IsMod , "Sam should not be a mod" )
expect ( t , ! user . IsBanned , "Sam should not be banned" )
2017-10-30 09:57:08 +00:00
_ , ferr = forumUserCheck ( dummyResponseRecorder , dummyRequest1 , user , reportsForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , ! user . Perms . ViewTopic , "Members shouldn't be able to access the reports forum" )
2017-10-30 09:57:08 +00:00
_ , ferr = forumUserCheck ( dummyResponseRecorder , dummyRequest2 , user2 , generalForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , user2 . Perms . ViewTopic , "Sam should be able to access the general forum" )
expect ( t , user . Perms . ViewTopic != user2 . Perms . ViewTopic , "user.Perms.ViewTopic and user2.Perms.ViewTopic should never match" )
err = user . ChangeGroup ( 4 )
expectNilErr ( t , err )
expect ( t , user . Group == 3 , "Someone's mutated this pointer elsewhere" )
user , err = users . Get ( newUserID )
recordMustExist ( t , err , "Couldn't find UID #%d" , newUserID )
expectIntToBeX ( t , user . ID , newUserID , "The UID of the user record should be %d" )
user2 = getDummyUser ( )
* user2 = * user
expect ( t , ! user . IsSuperAdmin , "Sam should not be a super admin" )
expect ( t , ! user . IsAdmin , "Sam should not be an admin" )
expect ( t , ! user . IsSuperMod , "Sam should not be a super mod" )
expect ( t , ! user . IsMod , "Sam should not be a mod" )
expect ( t , user . IsBanned , "Sam should be banned" )
2017-10-30 09:57:08 +00:00
_ , ferr = forumUserCheck ( dummyResponseRecorder , dummyRequest1 , user , reportsForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , ! user . Perms . ViewTopic , "Members shouldn't be able to access the reports forum" )
2017-10-30 09:57:08 +00:00
_ , ferr = forumUserCheck ( dummyResponseRecorder , dummyRequest2 , user2 , generalForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , user2 . Perms . ViewTopic , "Sam should be able to access the general forum" )
err = user . ChangeGroup ( 5 )
expectNilErr ( t , err )
expect ( t , user . Group == 4 , "Someone's mutated this pointer elsewhere" )
user , err = users . Get ( newUserID )
recordMustExist ( t , err , "Couldn't find UID #%d" , newUserID )
expectIntToBeX ( t , user . ID , newUserID , "The UID of the user record should be %d" )
user2 = getDummyUser ( )
* user2 = * user
expect ( t , ! user . IsSuperAdmin , "Sam should not be a super admin" )
expect ( t , ! user . IsAdmin , "Sam should not be an admin" )
expect ( t , ! user . IsSuperMod , "Sam should not be a super mod" )
expect ( t , ! user . IsMod , "Sam should not be a mod" )
expect ( t , ! user . IsBanned , "Sam should not be banned" )
2017-10-30 09:57:08 +00:00
_ , ferr = forumUserCheck ( dummyResponseRecorder , dummyRequest1 , user , reportsForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , ! user . Perms . ViewTopic , "Members shouldn't be able to access the reports forum" )
2017-10-30 09:57:08 +00:00
_ , ferr = forumUserCheck ( dummyResponseRecorder , dummyRequest2 , user2 , generalForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , user2 . Perms . ViewTopic , "Sam should be able to access the general forum" )
err = user . ChangeGroup ( 6 )
expectNilErr ( t , err )
expect ( t , user . Group == 5 , "Someone's mutated this pointer elsewhere" )
user , err = users . Get ( newUserID )
recordMustExist ( t , err , "Couldn't find UID #%d" , newUserID )
expectIntToBeX ( t , user . ID , newUserID , "The UID of the user record should be %d" )
user2 = getDummyUser ( )
* user2 = * user
expect ( t , ! user . IsSuperAdmin , "Sam should not be a super admin" )
expect ( t , ! user . IsAdmin , "Sam should not be an admin" )
expect ( t , ! user . IsSuperMod , "Sam should not be a super mod" )
expect ( t , ! user . IsMod , "Sam should not be a mod" )
expect ( t , ! user . IsBanned , "Sam should not be banned" )
2017-10-30 09:57:08 +00:00
_ , ferr = forumUserCheck ( dummyResponseRecorder , dummyRequest1 , user , reportsForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , ! user . Perms . ViewTopic , "Members shouldn't be able to access the reports forum" )
2017-10-30 09:57:08 +00:00
_ , ferr = forumUserCheck ( dummyResponseRecorder , dummyRequest2 , user2 , generalForumID )
expect ( t , ferr == nil , "There shouldn't be any errors in forumUserCheck" )
2017-10-21 00:27:47 +00:00
expect ( t , user2 . Perms . ViewTopic , "Sam should be able to access the general forum" )
err = user . ChangeGroup ( config . DefaultGroup )
expectNilErr ( t , err )
expect ( t , user . Group == 6 , "Someone's mutated this pointer elsewhere" )
2017-10-16 07:32:58 +00:00
err = user . Delete ( )
2017-10-21 00:27:47 +00:00
expectNilErr ( t , err )
expect ( t , ! users . Exists ( newUserID ) , fmt . Sprintf ( "UID #%d should no longer exist" , newUserID ) )
2017-10-16 07:32:58 +00:00
if hasCache {
expectIntToBeX ( t , ucache . Length ( ) , 0 , "User cache length should be 0, not %d" )
_ , err = ucache . CacheGet ( newUserID )
2017-10-21 00:27:47 +00:00
recordMustNotExist ( t , err , "UID #%d shouldn't be in the cache" , newUserID )
2017-10-16 07:32:58 +00:00
}
2017-10-21 00:27:47 +00:00
_ , err = users . Get ( newUserID )
recordMustNotExist ( t , err , "UID #%d shouldn't exist" , newUserID )
2017-11-05 01:04:57 +00:00
// TODO: Add tests for the Cache* methods
2017-10-21 00:27:47 +00:00
}
// TODO: Add an error message to this?
func expectNilErr ( t * testing . T , item error ) {
if item != nil {
debug . PrintStack ( )
t . Fatal ( item )
}
2017-10-16 07:32:58 +00:00
}
func expectIntToBeX ( t * testing . T , item int , expect int , errmsg string ) {
if item != expect {
debug . PrintStack ( )
t . Fatalf ( errmsg , item )
}
}
func expect ( t * testing . T , item bool , errmsg string ) {
if ! item {
debug . PrintStack ( )
2017-10-21 00:27:47 +00:00
t . Fatal ( errmsg )
2017-09-15 22:20:01 +00:00
}
}
2017-11-05 01:04:57 +00:00
func TestPermsMiddleware ( t * testing . T ) {
if ! gloinited {
err := gloinit ( )
if err != nil {
t . Fatal ( err )
}
}
if ! pluginsInited {
initPlugins ( )
}
dummyResponseRecorder := httptest . NewRecorder ( )
bytesBuffer := bytes . NewBuffer ( [ ] byte ( "" ) )
dummyRequest := httptest . NewRequest ( "" , "/forum/1" , bytesBuffer )
user := getDummyUser ( )
ferr := SuperModOnly ( dummyResponseRecorder , dummyRequest , * user )
expect ( t , ferr != nil , "Blank users shouldn't be supermods" )
user . IsSuperMod = false
ferr = SuperModOnly ( dummyResponseRecorder , dummyRequest , * user )
expect ( t , ferr != nil , "Non-supermods shouldn't be allowed through supermod gates" )
user . IsSuperMod = true
ferr = SuperModOnly ( dummyResponseRecorder , dummyRequest , * user )
expect ( t , ferr == nil , "Supermods should be allowed through supermod gates" )
// TODO: Loop over the Control Panel routes and make sure only supermods can get in
}
2017-09-15 22:20:01 +00:00
func TestTopicStore ( t * testing . T ) {
if ! gloinited {
err := gloinit ( )
if err != nil {
t . Fatal ( err )
}
}
if ! pluginsInited {
initPlugins ( )
}
2017-11-02 13:35:19 +00:00
var err error
topics , err = NewMemoryTopicStore ( config . TopicCacheCapacity )
expectNilErr ( t , err )
2017-09-15 22:20:01 +00:00
topicStoreTest ( t )
2017-11-02 13:35:19 +00:00
topics , err = NewSQLTopicStore ( )
expectNilErr ( t , err )
2017-09-15 22:20:01 +00:00
topicStoreTest ( t )
}
func topicStoreTest ( t * testing . T ) {
var topic * Topic
var err error
_ , err = topics . Get ( - 1 )
2017-10-21 00:27:47 +00:00
recordMustNotExist ( t , err , "TID #-1 shouldn't exist" )
2017-09-15 22:20:01 +00:00
_ , err = topics . Get ( 0 )
2017-10-21 00:27:47 +00:00
recordMustNotExist ( t , err , "TID #0 shouldn't exist" )
2017-09-15 22:20:01 +00:00
topic , err = topics . Get ( 1 )
2017-10-16 07:32:58 +00:00
recordMustExist ( t , err , "Couldn't find TID #1" )
2017-09-03 04:50:31 +00:00
2017-09-15 22:20:01 +00:00
if topic . ID != 1 {
t . Error ( "topic.ID does not match the requested TID. Got '" + strconv . Itoa ( topic . ID ) + "' instead." )
2017-09-03 04:50:31 +00:00
}
2017-09-15 22:20:01 +00:00
// TODO: Add BulkGetMap() to the TopicStore
ok := topics . Exists ( - 1 )
if ok {
t . Error ( "TID #-1 shouldn't exist" )
}
ok = topics . Exists ( 0 )
if ok {
t . Error ( "TID #0 shouldn't exist" )
}
ok = topics . Exists ( 1 )
2017-09-03 04:50:31 +00:00
if ! ok {
2017-09-15 22:20:01 +00:00
t . Error ( "TID #1 should exist" )
2017-09-03 04:50:31 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
count := topics . GlobalCount ( )
2017-09-15 22:20:01 +00:00
if count <= 0 {
t . Error ( "The number of topics should be bigger than zero" )
t . Error ( "count" , count )
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
}
2017-07-12 11:05:18 +00:00
}
func TestForumStore ( t * testing . T ) {
2017-09-03 04:50:31 +00:00
if ! gloinited {
2017-07-12 11:05:18 +00:00
gloinit ( )
}
2017-09-03 04:50:31 +00:00
if ! pluginsInited {
initPlugins ( )
}
2017-10-21 00:27:47 +00:00
_ , err := fstore . Get ( - 1 )
recordMustNotExist ( t , err , "FID #-1 shouldn't exist" )
2017-09-03 04:50:31 +00:00
2017-10-21 00:27:47 +00:00
_ , err = fstore . Get ( 0 )
recordMustNotExist ( t , err , "FID #0 shouldn't exist" )
2017-09-03 04:50:31 +00:00
2017-10-21 00:27:47 +00:00
forum , err := fstore . Get ( 1 )
2017-10-16 07:32:58 +00:00
recordMustExist ( t , err , "Couldn't find FID #1" )
2017-09-03 04:50:31 +00:00
if forum . ID != 1 {
2017-09-15 22:20:01 +00:00
t . Error ( "forum.ID doesn't not match the requested FID. Got '" + strconv . Itoa ( forum . ID ) + "' instead.'" )
2017-09-03 04:50:31 +00:00
}
2017-11-05 01:04:57 +00:00
// TODO: Check the preset and forum permissions
expect ( t , forum . Name == "Reports" , fmt . Sprintf ( "FID #0 is named '%s' and not 'Reports'" , forum . Name ) )
expect ( t , ! forum . Active , fmt . Sprintf ( "The reports forum shouldn't be active" ) )
var expectDesc = "All the reports go here"
expect ( t , forum . Desc == expectDesc , fmt . Sprintf ( "The forum description should be '%s' not '%s'" , expectDesc , forum . Desc ) )
2017-09-03 04:50:31 +00:00
2017-09-15 22:20:01 +00:00
forum , err = fstore . Get ( 2 )
2017-10-16 07:32:58 +00:00
recordMustExist ( t , err , "Couldn't find FID #1" )
2017-09-10 16:57:22 +00:00
2017-11-05 01:04:57 +00:00
expect ( t , forum . ID == 2 , fmt . Sprintf ( "The FID should be 2 not %d" , forum . ID ) )
expect ( t , forum . Name == "General" , fmt . Sprintf ( "The name of the forum should be 'General' not '%s'" , forum . Name ) )
expect ( t , forum . Active , fmt . Sprintf ( "The general forum should be active" ) )
expectDesc = "A place for general discussions which don't fit elsewhere"
expect ( t , forum . Desc == expectDesc , fmt . Sprintf ( "The forum description should be '%s' not '%s'" , expectDesc , forum . Desc ) )
2017-09-15 22:20:01 +00:00
ok := fstore . Exists ( - 1 )
2017-11-05 01:04:57 +00:00
expect ( t , ! ok , "FID #-1 shouldn't exist" )
2017-09-15 22:20:01 +00:00
ok = fstore . Exists ( 0 )
2017-11-05 01:04:57 +00:00
expect ( t , ! ok , "FID #0 shouldn't exist" )
2017-09-15 22:20:01 +00:00
ok = fstore . Exists ( 1 )
2017-11-05 01:04:57 +00:00
expect ( t , ok , "FID #1 should exist" )
// TODO: Test forum creation
// TODO: Test forum deletion
// TODO: Test forum update
}
// TODO: Implement this
func TestForumPermsStore ( t * testing . T ) {
if ! gloinited {
gloinit ( )
}
if ! pluginsInited {
initPlugins ( )
2017-09-15 22:20:01 +00:00
}
}
2017-11-05 01:04:57 +00:00
// TODO: Test the group permissions
2017-09-15 22:20:01 +00:00
func TestGroupStore ( t * testing . T ) {
if ! gloinited {
gloinit ( )
}
if ! pluginsInited {
initPlugins ( )
}
2017-10-21 00:27:47 +00:00
_ , err := gstore . Get ( - 1 )
recordMustNotExist ( t , err , "GID #-1 shouldn't exist" )
2017-09-15 22:20:01 +00:00
2017-10-16 07:32:58 +00:00
// TODO: Refactor the group store to remove GID #0
2017-10-21 00:27:47 +00:00
group , err := gstore . Get ( 0 )
2017-10-16 07:32:58 +00:00
recordMustExist ( t , err , "Couldn't find GID #0" )
2017-09-15 22:20:01 +00:00
if group . ID != 0 {
2017-10-21 00:27:47 +00:00
t . Errorf ( "group.ID doesn't not match the requested GID. Got '%d' instead." , group . ID )
2017-09-15 22:20:01 +00:00
}
2017-10-21 00:27:47 +00:00
expect ( t , group . Name == "Unknown" , fmt . Sprintf ( "GID #0 is named '%s' and not 'Unknown'" , group . Name ) )
2017-09-15 22:20:01 +00:00
group , err = gstore . Get ( 1 )
2017-10-16 07:32:58 +00:00
recordMustExist ( t , err , "Couldn't find GID #1" )
2017-09-15 22:20:01 +00:00
if group . ID != 1 {
2017-10-21 00:27:47 +00:00
t . Errorf ( "group.ID doesn't not match the requested GID. Got '%d' instead.'" , group . ID )
2017-09-15 22:20:01 +00:00
}
ok := gstore . Exists ( - 1 )
2017-10-21 00:27:47 +00:00
expect ( t , ! ok , "GID #-1 shouldn't exist" )
2017-09-15 22:20:01 +00:00
2017-10-21 00:27:47 +00:00
// 0 aka Unknown, for system posts and other oddities
2017-09-15 22:20:01 +00:00
ok = gstore . Exists ( 0 )
2017-10-21 00:27:47 +00:00
expect ( t , ok , "GID #0 should exist" )
2017-09-15 22:20:01 +00:00
ok = gstore . Exists ( 1 )
2017-10-21 00:27:47 +00:00
expect ( t , ok , "GID #1 should exist" )
var isAdmin = true
var isMod = true
var isBanned = false
gid , err := gstore . Create ( "Testing" , "Test" , isAdmin , isMod , isBanned )
expectNilErr ( t , err )
expect ( t , gstore . Exists ( gid ) , "The group we just made doesn't exist" )
group , err = gstore . Get ( gid )
expectNilErr ( t , err )
expect ( t , group . ID == gid , "The group ID should match the requested ID" )
expect ( t , group . IsAdmin , "This should be an admin group" )
expect ( t , group . IsMod , "This should be a mod group" )
expect ( t , ! group . IsBanned , "This shouldn't be a ban group" )
isAdmin = false
isMod = true
isBanned = true
gid , err = gstore . Create ( "Testing 2" , "Test" , isAdmin , isMod , isBanned )
expectNilErr ( t , err )
expect ( t , gstore . Exists ( gid ) , "The group we just made doesn't exist" )
group , err = gstore . Get ( gid )
expectNilErr ( t , err )
expect ( t , group . ID == gid , "The group ID should match the requested ID" )
expect ( t , ! group . IsAdmin , "This should not be an admin group" )
expect ( t , group . IsMod , "This should be a mod group" )
expect ( t , ! group . IsBanned , "This shouldn't be a ban group" )
// TODO: Make sure this pointer doesn't change once we refactor the group store to stop updating the pointer
err = group . ChangeRank ( false , false , true )
expectNilErr ( t , err )
group , err = gstore . Get ( gid )
expectNilErr ( t , err )
expect ( t , group . ID == gid , "The group ID should match the requested ID" )
expect ( t , ! group . IsAdmin , "This shouldn't be an admin group" )
expect ( t , ! group . IsMod , "This shouldn't be a mod group" )
expect ( t , group . IsBanned , "This should be a ban group" )
err = group . ChangeRank ( true , true , true )
expectNilErr ( t , err )
group , err = gstore . Get ( gid )
expectNilErr ( t , err )
expect ( t , group . ID == gid , "The group ID should match the requested ID" )
expect ( t , group . IsAdmin , "This should be an admin group" )
expect ( t , group . IsMod , "This should be a mod group" )
expect ( t , ! group . IsBanned , "This shouldn't be a ban group" )
err = group . ChangeRank ( false , true , true )
expectNilErr ( t , err )
group , err = gstore . Get ( gid )
expectNilErr ( t , err )
expect ( t , group . ID == gid , "The group ID should match the requested ID" )
expect ( t , ! group . IsAdmin , "This shouldn't be an admin group" )
expect ( t , group . IsMod , "This should be a mod group" )
expect ( t , ! group . IsBanned , "This shouldn't be a ban group" )
2017-11-05 01:04:57 +00:00
// Make sure the data is static
gstore . Reload ( gid )
group , err = gstore . Get ( gid )
expectNilErr ( t , err )
expect ( t , group . ID == gid , "The group ID should match the requested ID" )
expect ( t , ! group . IsAdmin , "This shouldn't be an admin group" )
expect ( t , group . IsMod , "This should be a mod group" )
expect ( t , ! group . IsBanned , "This shouldn't be a ban group" )
2017-10-21 00:27:47 +00:00
// TODO: Test group deletion
2017-11-05 01:04:57 +00:00
// TODO: Test group reload
// TODO: Test group cache set
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
}
2017-10-12 03:24:14 +00:00
func TestReplyStore ( t * testing . T ) {
if ! gloinited {
gloinit ( )
}
if ! pluginsInited {
initPlugins ( )
}
2017-10-21 00:27:47 +00:00
_ , err := rstore . Get ( - 1 )
recordMustNotExist ( t , err , "RID #-1 shouldn't exist" )
2017-10-12 03:24:14 +00:00
2017-10-21 00:27:47 +00:00
_ , err = rstore . Get ( 0 )
recordMustNotExist ( t , err , "RID #0 shouldn't exist" )
reply , err := rstore . Get ( 1 )
expectNilErr ( t , err )
2017-10-12 03:24:14 +00:00
if reply . ID != 1 {
2017-10-21 00:27:47 +00:00
t . Errorf ( "RID #1 has the wrong ID. It should be 1 not %d" , reply . ID )
2017-10-12 03:24:14 +00:00
}
if reply . ParentID != 1 {
2017-10-21 00:27:47 +00:00
t . Errorf ( "The parent topic of RID #1 should be 1 not %d" , reply . ParentID )
2017-10-12 03:24:14 +00:00
}
if reply . CreatedBy != 1 {
2017-10-21 00:27:47 +00:00
t . Errorf ( "The creator of RID #1 should be 1 not %d" , reply . CreatedBy )
2017-10-12 03:24:14 +00:00
}
}
func TestProfileReplyStore ( t * testing . T ) {
if ! gloinited {
gloinit ( )
}
if ! pluginsInited {
initPlugins ( )
}
_ , err := prstore . Get ( - 1 )
2017-10-21 00:27:47 +00:00
recordMustNotExist ( t , err , "RID #-1 shouldn't exist" )
2017-10-12 03:24:14 +00:00
_ , err = prstore . Get ( 0 )
2017-10-21 00:27:47 +00:00
recordMustNotExist ( t , err , "RID #0 shouldn't exist" )
2017-10-12 03:24:14 +00:00
}
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
func TestSlugs ( t * testing . T ) {
2017-09-03 04:50:31 +00:00
var res string
2017-09-13 15:09:13 +00:00
var msgList [ ] MEPair
2017-09-03 04:50:31 +00:00
msgList = addMEPair ( msgList , "Unknown" , "unknown" )
msgList = addMEPair ( msgList , "Unknown2" , "unknown2" )
msgList = addMEPair ( msgList , "Unknown " , "unknown" )
msgList = addMEPair ( msgList , "Unknown 2" , "unknown-2" )
msgList = addMEPair ( msgList , "Unknown 2" , "unknown-2" )
msgList = addMEPair ( msgList , "Admin Alice" , "admin-alice" )
msgList = addMEPair ( msgList , "Admin_Alice" , "adminalice" )
msgList = addMEPair ( msgList , "Admin_Alice-" , "adminalice" )
msgList = addMEPair ( msgList , "-Admin_Alice-" , "adminalice" )
msgList = addMEPair ( msgList , "-Admin@Alice-" , "adminalice" )
msgList = addMEPair ( msgList , "-Admin😀Alice-" , "adminalice" )
msgList = addMEPair ( msgList , "u" , "u" )
msgList = addMEPair ( msgList , "" , "untitled" )
msgList = addMEPair ( msgList , " " , "untitled" )
msgList = addMEPair ( msgList , "-" , "untitled" )
msgList = addMEPair ( msgList , "--" , "untitled" )
msgList = addMEPair ( msgList , "é" , "é" )
msgList = addMEPair ( msgList , "-é-" , "é" )
2017-11-05 01:04:57 +00:00
msgList = addMEPair ( msgList , "-你好-" , "untitled" )
2017-09-03 04:50:31 +00:00
for _ , item := range msgList {
t . Log ( "Testing string '" + item . Msg + "'" )
res = nameToSlug ( item . Msg )
if res != item . Expects {
t . Error ( "Bad output:" , "'" + res + "'" )
t . Error ( "Expected:" , item . Expects )
}
}
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
}
2017-07-12 11:05:18 +00:00
func TestAuth ( t * testing . T ) {
2017-09-03 04:50:31 +00:00
// bcrypt likes doing stupid things, so this test will probably fail
var realPassword string
var hashedPassword string
var password string
var salt string
var err error
/* No extra salt tests, we might not need this extra salt, as bcrypt has it's own? */
realPassword = "Madame Cassandra's Mystic Orb"
2017-10-21 00:27:47 +00:00
t . Log ( "Set realPassword to '" + realPassword + "'" )
2017-09-03 04:50:31 +00:00
t . Log ( "Hashing the real password" )
hashedPassword , err = BcryptGeneratePasswordNoSalt ( realPassword )
if err != nil {
t . Error ( err )
}
password = realPassword
t . Log ( "Testing password '" + password + "'" )
t . Log ( "Testing salt '" + salt + "'" )
err = CheckPassword ( hashedPassword , password , salt )
if err == ErrMismatchedHashAndPassword {
t . Error ( "The two don't match" )
} else if err == ErrPasswordTooLong {
t . Error ( "CheckPassword thinks the password is too long" )
} else if err != nil {
t . Error ( err )
}
password = "hahaha"
t . Log ( "Testing password '" + password + "'" )
t . Log ( "Testing salt '" + salt + "'" )
err = CheckPassword ( hashedPassword , password , salt )
if err == ErrPasswordTooLong {
t . Error ( "CheckPassword thinks the password is too long" )
} else if err == nil {
t . Error ( "The two shouldn't match!" )
}
password = "Madame Cassandra's Mystic"
t . Log ( "Testing password '" + password + "'" )
t . Log ( "Testing salt '" + salt + "'" )
err = CheckPassword ( hashedPassword , password , salt )
if err == ErrPasswordTooLong {
t . Error ( "CheckPassword thinks the password is too long" )
} else if err == nil {
t . Error ( "The two shouldn't match!" )
}
2017-07-12 11:05:18 +00:00
}